You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 29, 2023. It is now read-only.
This is broader than just Maybe, but I'm not sure if you can create issues for a whole group. Anyhow, I've been working on an implementation of Task, and found myself wanting a liftA2() function. It struck me that there's at least three ways to approach how I declare the function signature:
Option 1: Nailed-down types
functionliftA2(callable$f, Task$a1, Task$a2) {
return$a1->map(function ($a1Val) use ($f) {
returnfunction($x) use ($a1Val) {
return$f($a1Val, $x);
}
})->ap($a2);
}
Option 2: No type checking
functionliftA2(callable$f, $a1, $a2) {
return$a1->map(function ($a1Val) use ($f) {
returnfunction($x) use ($a1Val) {
return$f($a1Val, $x);
}
})->ap($a2);
}
Option 3: Interface type checking
functionliftA2(callable$f, Functor$a1, Applicative$a2) {
return$a1->map(function ($a1Val) use ($f) {
returnfunction($x) use ($a1Val) {
return$f($a1Val, $x);
}
})->ap($a2);
}
Option 1 works, but isn't terribly flexible. Option 2 also works, until someone tries to pass in something without a ->ap() or ->map() method. I could manually check for the given method with reflection, but it seems a pain. Option 3 would mean that PHP did the checking for me, and would allow me to re-use liftA2() across different types. But it would also mean that I have to make sure that all the types I want to use it with implement that interface.
I haven't actually tried it, so I don't know if there's good reasons not to. Is this something you've thought about?