Download the PHP package haskellcamargo/php-maybe-monad without Composer
On this page you can find all versions of the php package haskellcamargo/php-maybe-monad. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download haskellcamargo/php-maybe-monad
More information about haskellcamargo/php-maybe-monad
Files in haskellcamargo/php-maybe-monad
Package php-maybe-monad
Short Description A PHP implementation of Haskell's Maybe monad
License MIT
Informations about the package php-maybe-monad
PHP Maybe Monad
To deal with computations that may fail.
A port of Haskell's Data.Maybe module for PHP > 5.4.
Install
You can install via Composer.
Example
Documentation
A Maybe type encapsulates an optional value. A value of type Maybe a
either contains a value of type a (represented as Just a), or it is empty
(represented as Nothing). Using Maybe is a good way to deal with errors
or exceptional cases without resorting to drastic measures such as
Exception.
The Maybe type is also a monad. It is a simple kind of error monad, where
all errors are represented by Nothing. A richer error monad can be built
using the Either type.
bind :: (Maybe a, callable) -> Maybe b
Equivalent to Haskell's >>= operator. Its first argument is a value in
a monadic type, its second argument is a function that maps from the
underlying type of the first argument to another monadic type, and its
results is in that other monadic type.
fromJust :: Maybe a -> a
Extracts the element out of a Just and returns an error if its argument
is Nothing.
fromMaybe :: (Maybe a, a) -> a
Takes a Maybe value and a default value. If the Maybe is Nothing, it
returns the default values; otherwise, it returns the value contained in
the Maybe.
isJust :: Maybe a -> boolean
Returns true if its argument is of the form Just _.
isNothing :: Maybe a -> boolean
Returns true if its argument is of the form Nothing.
maybe :: (Maybe a, b, callable) -> b
Takes a default value, a function and, of course, a Maybe value. If the
Maybe value is Nothing, the function returns the default value.
Otherwise, it applies the function to the value inside the Just and
returns the result.
toList :: Maybe a -> array
Returns an empty list when given Nothing or a singleton list when not
given Nothing.
Made with :heart: by Marcelo Camargo and Reinaldo Rauch
License
MIT