-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
port Haskell partitionEithers #38
Comments
Closing this as I don't see a good way to do it generically. |
partition :: forall f g a b. Foldable f => Unfoldable g => f (Either a b) -> Tuple (g a) (g b) ? |
It would require two traversals, granted. |
Yeah, that does work. What do people think of adding both |
Thanks for this. Will do it. |
I think this should be added, but I'm hesitant because of the dependencies one would need to add. |
An alternative that I came up with based on catMaybes: catLefts :: forall a b m. Monad m => Plus m => m (Either a b) -> m a
catLefts = catMapLefts identity
catMapLefts :: forall a b c m. Monad m => Plus m
=> (a -> c) -> m (Either a b) -> m c
catMapLefts f = (flip bind) (leftOr empty (pure <<< f))
leftOr :: forall a b c. c -> (a -> c) -> Either a b -> c
leftOr _ f (Left a) = f a
leftOr c _ (Right _) = c I don't think this requires any additional dependencies on this package - correct me if I'm wrong. Would a PR with this (and the related |
I would be concerned about the performance of that function, and I’d also worry that it might not behave performantly or even sensibly for some types which don’t have append-y Plus instances (like Effect). I think I’d be unlikely to approve adding that to core; the Filterable formulation is more appealing to me. In general, I think things which haven’t already been tested and found to be effective and useful in practice shouldn’t go straight into core. This is because it’s much more expensive to change stuff once it’s in core since so many more people will he depending on it, and because enlarging core puts more maintenance burden on the core team. I’d suggest putting them in your own library for now (or switching to Filterable). |
Thanks! The performance didn't look great to me either, though I hadn't thought of Effect having a Plus instance. I mainly went this way as |
Closing as Filterable enables this. |
(And is now a core library, which wasn’t previously true!) |
from
base
(https://hackage.haskell.org/package/base-4.11.1.0/docs/Data-Either.html):suggested PS equivalent:
The text was updated successfully, but these errors were encountered: