mirror of
https://code.sup39.dev/repos/Wqawg
synced 2024-12-31 04:44:51 +09:00
Data.List.Local: Generalize input list to be any Foldable
This commit is contained in:
parent
c8146bbff4
commit
16c71b666f
1 changed files with 2 additions and 2 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue