{
return $this->value;
}
+
+ /**
+ * foldl _ z Nothing = z
+ * foldl f z (Just x) = f z x
+ *
+ * @inheritdoc
+ */
+ public function reduce(callable $function, $accumulator)
+ {
+ return $function($accumulator, $this->value);
+ }
}
{
return null;
}
+
+ /**
+ * foldl _ z Nothing = z
+ * foldl f z (Just x) = f z x
+ *
+ * @inheritdoc
+ */
+ public function reduce(callable $function, $accumulator)
+ {
+ return $accumulator;
+ }
}
namespace test\Functional;
use Widmogrod\Functional as f;
+use Widmogrod\Monad\Maybe\Just;
+use Widmogrod\Monad\Maybe\Nothing;
class ConcatTest extends \PHPUnit\Framework\TestCase
{
3
]),
],
+ 'Just of lists' => [
+ '$array' => Just::of(f\fromIterable(['a', 1, 3])),
+ '$expected' => f\fromIterable(['a', 1, 3]),
+ ],
+ 'Nothing of lists' => [
+ '$array' => Nothing::mempty(),
+ '$expected' => f\fromNil()
+ ],
];
}
}