Commit before changing thingsHit to use stream

This commit is contained in:
2022-06-26 11:37:43 +01:00
parent 6c571d1878
commit f47059ae9b
5 changed files with 15 additions and 35 deletions
+9
View File
@@ -7,6 +7,7 @@ module FoldableHelp
, safeMinMaybeL
, filter3
, takeUntil
, ssfold
, module Data.Foldable
)
where
@@ -91,3 +92,11 @@ filter3 t1 t2 t3 = L.fold $ (,,)
-}
takeUntil :: Foldable t => (a -> Bool) -> t a -> [a]
takeUntil p = foldr (\x xs -> x : if p x then [] else xs) []
-- from haskell-cafe
-- short circuit a fold when a given property is satisfied
-- the fold builds a function that is then called on a0
ssfold :: Foldable t => (a -> Bool) -> (a -> b -> a) -> a -> t b -> a
{-# INLINABLE ssfold #-}
ssfold p f a0 xs = foldr (\x g a -> if p a then a else g (f a x)) id xs a0