private function ifMatch(callable $matcher, callable $predicate, callable $action) : Optional { return $this->bindMonad(sequence(conditionally(curry($matcher, 2)($predicate), $action), optional)); }
/** * Invoke a value if it is callable. * * @param array $args optional array of arguments to pass to the optional callable * @return Chain the result of the invocation wrapped into a Chain, or empty Chain */ public function invokeArray(array $args = []) : Chain { return $this->continue(conditionally(is_callable, curry(reverse(call_user_func_array), 2)($args))); }
/** * Filter a value of the monad by a predicate. * * If the value matches the predicate, this monad will be returned, * otherwise monad with NULL value will be returned. * * @param callable $predicate the predicate to test the value * @return Optional this monad if the value matches the predicate, * otherwise a monad with NULL value */ public function filter(callable $predicate) : Optional { return $this->bind(conditionally($predicate, pass_through)); }