Generalised Partition for all Fallible monads #1405
louthy
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In this release there are now generalised
Partition,Succs, andFailsmethods (and their equivalentPreludefunctions:partition,succs, andfails) that work with anyFoldableofFalliblemonads.This is the main
Partitionextension:So, if your
Fis aIterableand yourMis anIO(soIterable<IO<A>>), then you can runPartitionon that to get aIO<(Seq<Error> Fails, Seq<A> Succs)>. Obviously this will work with anyFoldabletypes you have made too (as well as all the built-in ones:Arr,Lst,Iterable,Seq,Set,HashSet, etc.) -- with any effect type as long as itsFallibleand aMonad. IncludingFallibletypes with a bespokeEerror value (but you will have to specify the generics as it can't infer from the arguments alone).I have also added a
Partitionextension andpartitionprelude function that works with anyFoldablestructure. Unlike thePartitionfunction that works withFallibletypes (which partitions on success or failure), this one takes a predicate which is used to partition based on thetrue/falsereturn. It's likeFilterbut instead of throwing away thefalsevalues, it keeps them and returns aTruesequence andFalsesequence:All foldables get a default implementation, but it's possible to override in the trait-implementation (for performance reasons mostly).
Finally, I've added unit-tests for the
Foldabledefault-implementations. Anybody who's been following along will know that theFoldabletrait only has two methods that need implementing and over 50 default implementations that we get for free. So, the unit test makes sure they work! (which should guarantee they work for all foldables as long as the two required method-implementations are correct).I'm considering how I can refactor those unit-tests into a
FoldableLawtype that will work likeMonadLaw,FunctorLaw, etc. But that's not there yet.This discussion was created from the release Generalised Partition for all Fallible monads.
Beta Was this translation helpful? Give feedback.
All reactions