Skip to content

Commit 8c3f304

Browse files
Add chainl1 to ParserK
1 parent d330733 commit 8c3f304

File tree

1 file changed

+14
-0
lines changed
  • core/src/Streamly/Internal/Data/ParserK

1 file changed

+14
-0
lines changed

core/src/Streamly/Internal/Data/ParserK/Type.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module Streamly.Internal.Data.ParserK.Type
3232
, fromPure
3333
, fromEffect
3434
, die
35+
, chainl1
3536

3637
, parserDone
3738

@@ -538,3 +539,16 @@ toParser parser = ParserD.Parser step initial extract
538539
forall s. toParser (parserK s) = s #-}
539540
{-# RULES "toParser/fromParser fusion" [2]
540541
forall s. parserK (toParser s) = s #-}
542+
543+
{-# INLINE chainl1 #-}
544+
chainl1 :: ParserK b IO a -> ParserK b IO (a -> a -> a) -> ParserK b IO a
545+
chainl1 p op = p >>= go
546+
547+
where
548+
549+
go l = step l <|> pure l
550+
551+
step l = do
552+
c <- op
553+
r <- p
554+
go (c l r)

0 commit comments

Comments
 (0)