1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-31 05:54:50 +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] -- >>> groupJusts [Nothing, Nothing, Just 1, Just 4, Nothing, Just 2]
-- [[1, 4], [2]] -- [[1, 4], [2]]
groupJusts :: [Maybe a] -> [NonEmpty a] groupJusts :: Foldable f => f (Maybe a) -> [NonEmpty a]
groupJusts maybes = prepend $ foldr go (Nothing, []) maybes groupJusts maybes = prepend $ foldr go (Nothing, []) maybes
where where
prepend (Nothing, l) = l 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) (Nothing, ls) = (Just $ x :| [], ls)
go (Just x) (Just l , ls) = (Just $ x <| l , 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 ([], [], []) groupEithers = foldr go ([], [], [])
where where
go (Left x) ([] , [] , as) = ([], [] , x : as) go (Left x) ([] , [] , as) = ([], [] , x : as)