Download the PHP package widmogrod/php-functional without Composer

On this page you can find all versions of the php package widmogrod/php-functional. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-functional

PHP Functional

Build Status Test Coverage Maintainability

Introduction

Functional programing is a fascinating concept. The purpose of this library is to explore Functors, Applicative Functors and Monads in OOP PHP, and provide examples of real world use case.

Monad types available in the project:

Exploring functional programing space I noticed that working with primitive values from PHP is very hard and complicates implementation of many functional structures. To simplify this experience, set of higher order primitives is introduced in library:

Applications

Known applications of this project

Installation

Development

This repository follows semantic versioning concept. If you want to contribute, just follow CONTRIBUTING.md

Testing

Quality assurance is brought to you by:

Use Cases

You can find more use cases and examples in the example directory.

NOTE: Don't be confused when browsing thought examples you will see phrase like "list functor" and in this library you will see Widmogrod\Primitive\Listt. Monad is Functor and Applicative. You could say that Monad implements Functor and Applicative.

List Functor

List Applicative Functor

Apply function on list of values and as a result, receive list of all possible combinations of applying function from the left list to a value in the right one.

Maybe Monoid

Using Maybe as an instance of Monoid simplifies concat and reduce operations by using Maybe's abstraction over potentially missing values. See an example of constructing a person's full name from first, middle, and last without having to explicitly check if each part exists.

Maybe and List Monad

Extracting from a list of uneven values can be tricky and produce nasty code full of if (isset) statements. By combining List and Maybe Monad, this process becomes simpler and more readable.

Either Monad

In php world, the most popular way of saying that something went wrong is to throw an exception. This results in nasty try catch blocks and many of if statements. Either Monad shows how we can fail gracefully without breaking the execution chain and making the code more readable. The following example demonstrates combining the contents of two files into one. If one of those files does not exist the operation fails gracefully.

IO Monad

Example usage of IO Monad. Read input from stdin, and print it to stdout.

Writer Monad

The Writer monad is useful to keep logs in a pure way. Coupled with filterM for example, this allows you to know exactly why an element was filtered.

Reader Monad

The Reader monad provides a way to share a common environment, such as configuration information or class instances, across multiple functions.

Free Monad in PHP

Imagine that you first write business logic and don't care about implementation details like:

When your business logic is complete, then you can concentrate on those details.

Free monad enables you to do exactly that, and more:

Echo program

Example Free Monad example of echo program can be found here:

DSL for BDD tests

Example that use Free Monad to creates simple DSL (Domain Specific Language) to define BDD type of framework:

Free Monad Calculator example

Example of a DSL for a naive calculator that is implemented by using FreeMonad.

Free monad can be interpreted as a real calculator or calculation formatter a.k.a. pretty printer. Additional thing that I wanted to tackle was a Free Monad Optimisation.

Considering that Free Monad is like AST, question arose in my mind - can I travers it and update it to simplify computation? Hot to do it? What are limitation of Free Monad? Calculator example is an outcome of those questions.

Haskell do notation in PHP

Why Haskell's do notation is interesting?

In Haskell is just an "syntax sugar" and in many ways is not needed, but in PHP control flow of monads can be hard to track.

Consider example, that use only chaining bind() and compare it to the same version but with do notation in PHP.

Control flow without do notation

Control flow with do notation

Everyone needs to judge by itself, but in my opinion do notationimprove readability of code in PHP.

Book Functional PHP by Gilles Crettenand

In recently published book Functional PHP by Gilles Crettenand, you can learn more applications of widmogrod/php-functional, see how it compares to other projects and how in an effortless way apply functional thinking in daily work.

Buy the book at PacktPub

References

Here links to their articles/libraries that help me understood the domain:


All versions of php-functional with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1|^8.0
functional-php/fantasy-land Version ^1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package widmogrod/php-functional contains the following files

Loading the files please wait ....