Skip to content

Commit 4188fec

Browse files
torgeirshtreeowl
authored andcommitted
Add untilLeft function that mirrors untilRight
1 parent a591744 commit 4188fec

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/Streaming/Prelude.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ module Streaming.Prelude (
7070
, repeat
7171
, repeatM
7272
, replicate
73+
, untilLeft
7374
, untilRight
7475
, cycle
7576
, replicateM
@@ -2140,6 +2141,18 @@ unfoldr step = loop where
21402141
Right (a,s) -> return (Step (a :> loop s)))
21412142
{-# INLINABLE unfoldr #-}
21422143

2144+
-- ---------------------------------------
2145+
-- untilLeft
2146+
-- ---------------------------------------
2147+
untilLeft :: Monad m => m (Either r a) -> Stream (Of a) m r
2148+
untilLeft act = Effect loop where
2149+
loop = do
2150+
e <- act
2151+
case e of
2152+
Right a -> return (Step (a :> Effect loop))
2153+
Left r -> return (Return r)
2154+
{-# INLINABLE untilLeft #-}
2155+
21432156
-- ---------------------------------------
21442157
-- untilRight
21452158
-- ---------------------------------------

0 commit comments

Comments
 (0)