Widmogrod\Monad\IO::bind PHP Method

bind() public method

bind :: IO a -> (a -> IO b) -> IO b
public bind ( callable $function )
$function callable
    public function bind(callable $function)
    {
        // Theoretical here should be call like this:
        //  call_user_func($function, $this->run())
        // But this do not make things lazy, to cheat little bit
        // IO monad is returned and inside of it is little switch
        return static::of(function () use($function) {
            $m = call_user_func($function, $this->run());
            return $m instanceof IO ? $m->run() : $m;
        });
    }