Download the PHP package md/for-comprehension-preprocessor without Composer

On this page you can find all versions of the php package md/for-comprehension-preprocessor. 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 for-comprehension-preprocessor

A for-comprenhensions pre-processor for PHP

For-comprenhensions are syntax sugar for composing certain group of operations that can be found in monadic collections: withEach, withFilter, filter, map and flatMap. This pre-processor will translate the operations using the for-comprenhension syntax into pure PHP. This does not happen at runtime, so there is no hit on perfomance. The pre-processor works on top of the pre plugin and the yay macro library.

Let's see how it works in practice with iteration, filtering, mapping and flatmapping.

Iteration

gets translated to:

which prints

Ok, that's boring. PHP foreach does the same. Or does it? With this syntax you can do many iterations in one go.

which translates to:

and prints

Hmm! Starting to be interesting, huh? Oh! but's this is really nothing yet.

Mapping

When using the yield keyword, one-liner for-comprehensions translate to mapping:

this becomes:

which produces a ImmList(2, 3, 4).

Flatmapping

You can compose these expressions to create bigger expressions. When you add lines to your for-comprehension you get them translated into flatMap operations, only the last one remains a map.

which gets translated into:

This is actually a very common pattern in functional programming and a very good way to keep operations within a pure context. The code below has no side effects and describes IO operations in a functional program.

Notice that you can use the wildcard _ to ignore the return values of operations. The yield () will return a IO<Unit>. A unit is an empty product. If you are new to this, just think of it as a void. It's not, but that would do for now.

Filtering

As we add operations to the for comprenhension we can add filters that will operate on the result of such operations, limiting what's given to the next operation.

this code is translated into:

The result is a new List with only the elements that satisfy the predicate $a % 2 == 0 or, in order words, are even.

A more complex example

which translate to:

We can also add the filters in the next line:

Which is the equivalent of having the filter next to the previous line.

Note that the pre-processor recognises tuples syntax, so you can return tuples and have them assigned to more than one varible:

which translate to:

or you can return tuples:

which maps to Some(Pair(42,43)).

Final Notes


All versions of for-comprehension-preprocessor with dependencies

PHP Build Version
Package Version
Requires yay/yay Version ^0.2
pre/plugin Version ^0.7.3
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 md/for-comprehension-preprocessor contains the following files

Loading the files please wait ....