library submission: Data.Either.unzipEithers :: [Either a b] ->
([a], [b])
Conor McBride
ctm at cs.nott.ac.uk
Mon Sep 17 08:51:34 EDT 2007
Folks
On 17 Sep 2007, at 12:57, Ian Lynagh wrote:
> On Fri, Sep 14, 2007 at 01:12:41PM -0700, Jeremy Shaw wrote:
>> http://hackage.haskell.org/trac/ghc/ticket/1695
>
> You haven't suggested a deadline. As the GHC release and ICFP et al
> are
> coming up, how about 15 October to give people a chance to comment?
>
>> This function is like unzip for a list of Eithers instead of tuples.
>
> Seems fine to me.
For your general amusement, a generalisation:
> separate :: (Traversable t, Applicative a, Monoid (a x), Monoid (a
y)) =>
> t (Either x y) -> (a x, a y)
> separate = foldMap (either (pure &&& mempty) (mempty &&& pure))
I don't know whether the applicative/monoid(*) output generalisation is
especially useful, but the shift to any traversable input might come in
handy. Then again, one could always turn the traversable thing into a
list first, using (foldMap pure).
General question: how often does a one-liner need to show up in common
usage to get into the library? You can really go a long way in one line!
(*) foldMap needs a Monoid, so Alternative is not a suitable
alternative;
as ever, it would be nice to be able to demand (forall x. Monoid (a x))
or some such.
All the best
Conor
More information about the Libraries
mailing list