Download the PHP package php-fp/php-fp-either without Composer

On this page you can find all versions of the php package php-fp/php-fp-either. 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-fp-either

The Either Monad for PHP. Build Status

Intro

When you throw an exception in PHP, you effectively perform a GOTO: your position in the program's execution jumps to the appropriate exception handler, and execution continues. This is fine, but it obviously means that your original function has a side-effect: calling it will fundamentally alter the program flow. What we need is a functional way of accomplishing the same thing.

Enter, the Either monad. Either has two constructors, Left and Right. These work very similarly to Maybe's Just and Nothing: map, ap, and chain work as you'd expect on the Right instance, but are effectively no-ops on the Left. However, the difference is that Left, unlike Nothing, holds a value.

This means that, typically, your left branch will hold the 'exception', and the right will hold the value. If an exception happens, all future computations are ignored, and the exception can be handled in a pure way. For example:

As the above shows, a failure is carried through the computation and all further operations (with the only (for now) exception of bimap below), and must be handled by either, the function for retrieving the inner value.

Of course, exceptions are the usual analogy, but Either is a more general type, and is helpful in most computations with two potential values. What if a user can input via a file or stdin? We could use Either String File, map over the instance with a File -> String function, then extract the value once we know they're both acceptable.

API

In the following type signatures, constructors and static functions are written as one would see in pure languages such as Haskell. The others contain a pipe, where the type before the pipe represents the type of the current Either instance, and the type after the pipe represents the function.

of :: a -> Either e a

This is the applicative constructor for the Either monad. It returns the given value wrapped in a Right instance:

left :: a -> Left e a

Standard constructor for Left instances.

right :: a -> Right e a

Standard constructor for Right instances. Typically you should call Either::of instead.

tryCatch :: (-> a) -> Either e a

Sometimes, you will have a piece of exception-throwing code that you wish to wrap in an Either, and this function can help. If an exception occurs, it will be wrapped and returned in a Left. Otherwise, the returned value will be wrapped in a Right:

ap :: Either e (a -> b) | Either e a -> Either e b

Apply an Either-wrapped argument to an Either-wrapped function, where a Left function will behave as identity.

bimap :: Either e a | (e -> f) -> (a -> b) -> Either f b

Sometimes, it can be useful to define computations to be performed on the Left values, and this is the way to do so. For this function, you supply left and right transformations, and the appropriate one will be used:

chain :: Either e a | (a -> Either f b) -> Either f b

The standard monadic binding function (Haskell's >>=). This is for mapping with a function that returns an Either value: instead of using map and getting Either e (Either e a), you get Either e a and the two levels are "flattened". The introduction has a good example, but here's a smaller one:

map :: Either e a | (a -> b) -> Either e b

This is the standard functor map, which transforms the inner value. As with the other Either operations, remember that this has no impact on a Left value, which can only be transformed with bimap:

either :: Either e a | (e -> b) -> (a -> b) -> b

This is the function that should be used to get the value out of the Either monad. Strictly, if you're being well-behaved and watching your types, the two supplied functions, while potentially accepting differently-typed inputs for Left and Right, should return values of the same type:

Contributing

Similarly to the others, I'm aware of at least a couple of typeclasses that could be added to this implementation, so feel free to submit issues or PRs if you'd like to see others included.

However, the much more pressing concern is with the documentation: if something isn't crystal clear, please leave an issue or submit a suggested fix in order to make this as clear and descriptive as possible!


All versions of php-fp-either with dependencies

PHP Build Version
Package Version
No informations.
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 php-fp/php-fp-either contains the following files

Loading the files please wait ....