1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-28 22:44:51 +09:00

Data.List.Local: Generalize input list to be any Foldable

This commit is contained in:
fr33domlover 2018-07-08 21:57:08 +00:00
parent c8146bbff4
commit 16c71b666f

View file

@ -37,7 +37,7 @@ import Data.List.NonEmpty (NonEmpty (..), (<|))
--
-- >>> groupJusts [Nothing, Nothing, Just 1, Just 4, Nothing, Just 2]
-- [[1, 4], [2]]
groupJusts :: [Maybe a] -> [NonEmpty a]
groupJusts :: Foldable f => f (Maybe a) -> [NonEmpty a]
groupJusts maybes = prepend $ foldr go (Nothing, []) maybes
where
prepend (Nothing, l) = l
@ -47,7 +47,7 @@ groupJusts maybes = prepend $ foldr go (Nothing, []) maybes
go (Just x) (Nothing, ls) = (Just $ x :| [], ls)
go (Just x) (Just l , ls) = (Just $ x <| l , ls)
groupEithers :: [Either a b] -> ([b], [(NonEmpty a, NonEmpty b)], [a])
groupEithers :: Foldable f => f (Either a b) -> ([b], [(NonEmpty a, NonEmpty b)], [a])
groupEithers = foldr go ([], [], [])
where
go (Left x) ([] , [] , as) = ([], [] , x : as)