on master help sign in
Add some common parser idioms using splitWith
d42276aAdithya Kumar
src/Streamly/Internal/Data/Parser.hs+18
@@ -694,6 +694,24 @@ eqBy cmp = K.toParserK . D.eqBy cmp
694-- operations and can be faster than 'Applicative' instance for small number
694-- operations and can be faster than 'Applicative' instance for small number
695-- (less than 8) of compositions.
695-- (less than 8) of compositions.
696--
696--
697+-- Many combinators can be expressed using @splitWith@ and other parser
698+-- primitives. Some common idioms are described below,
699+--
700+-- @
701+-- span :: (a -> Bool) -> Fold m a b -> Fold m a b -> Parser m a b
702+-- span pred f1 f2 = splitWith (,) ('takeWhile' pred f1) ('fromFold' f2)
703+-- @
704+--
705+-- @
706+-- spanBy :: (a -> a -> Bool) -> Fold m a b -> Fold m a b -> Parser m a b
707+-- spanBy eq f1 f2 = splitWith (,) ('groupBy' eq f1) ('fromFold' f2)
708+-- @
709+--
710+-- @
711+-- spanByRolling :: (a -> a -> Bool) -> Fold m a b -> Fold m a b -> Parser m a b
712+-- spanByRolling eq f1 f2 = splitWith (,) ('groupByRolling' eq f1) ('fromFold' f2)
713+-- @
714+--
697-- /Internal/
715-- /Internal/
698--
716--
699{-# INLINE splitWith #-}
717{-# INLINE splitWith #-}