DEV Community

lray138
lray138

Posted on

Mad For Monads

When I loaded up this site this article sat at the top of the feed. https://dev.to/sylwia-lask/how-i-almost-burned-out-doing-everything-right-31j6?

Well, I'm burned out. I've been burned out.

I never even wanted to be a programmer... how did I get here?

function tryPartial($partial, $args = null): Result
{
    $result = getPartialCallable(Str::of($partial))
        ->map(fn($callable) => fn(array $args) => Str::of($callable($args)));

    if (func_num_args() >= 2) {
        return $result->ap(Result::of($args));
    }

    return $result;
}
Enter fullscreen mode Exit fullscreen mode

that was the updated function from:

function tryPartial($partial, $args = []): Result {
     $out = getPartialCallable(Str::of($partial))
         ->map(fn($callable) => Str::of($callable($args)));
     return $out;
}
Enter fullscreen mode Exit fullscreen mode

Where I realized if tryPartial was curried I could return the Result which would contain the functional component and then I could use ap on the Result to apply the data and return the result of the function with is a string of HTML.

Top comments (0)