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
@deleite this doesn't quite work, if you look at the type signature, the end result should be a Either e a. There's little we know about e but we can settle on an Error or String here. However, we know that a must be the same type of the a also provided in input for the predicate. So instead of Either.of(predicate), you should return Either.of(v).
You could write it the following way:
// fromPredicate :: (a -> Bool) -> a -> Either e aconstfromPredicate=curry((predicate,a)=>predicate(a)
? newRight(a)
: newLeft("predicate failed"));// --- exampleconstpredicate=s=>s.startsWith("a",s);constfruitsA=newList(["apple","pear","banana","apricot","orange"]);constfruitsB=newList(["apple","apricot"]);validate(predicate)(fruitsA);// Left('predicate failed')validate(predicate)(fruitsB);// Right({$value: ['apple', 'apricot']})
Could some help me understand the fromPredicate example in the:
https://github.com/MostlyAdequate/mostly-adequate-guide/blob/master/ch12.md#effect-assortment
I get that the first one would keep the lefts and rights and the second won't but I would like to see it running so it is easier to get the idea.
Thanks
The text was updated successfully, but these errors were encountered: