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:
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]
|
||||
-- [[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)
|
||||
|
|
Loading…
Reference in a new issue