Inheritance: implements Widmogrod\Monad\Either\Either, use trait Widmogrod\Common\PointedTrait, use trait Widmogrod\Common\ValueOfTrait
Example #1
0
 public function provideFunctorTestData()
 {
     return ['Right' => ['$f' => function ($x) {
         return $x + 1;
     }, '$g' => function ($x) {
         return $x + 5;
     }, '$x' => Right::of(1)], 'Left' => ['$f' => function ($x) {
         return $x + 1;
     }, '$g' => function ($x) {
         return $x + 5;
     }, '$x' => Left::of(1)]];
 }
Example #2
0
/**
 * left :: a -> Left a
 *
 * @param mixed $value
 *
 * @return Left
 */
function left($value)
{
    return Left::of($value);
}
function read($file)
{
    return is_file($file) ? Either\Right::of(file_get_contents($file)) : Either\Left::of(sprintf('File "%s" does not exists', $file));
}
function validateNameLength(array $request)
{
    return strlen($request['name']) > 30 ? E\Left::of('Request name is to long') : E\Right::of($request);
}