@@ -76,6 +76,10 @@ module Streamly.Internal.Data.Parser
76 , sepWithPrefix
76 , sepWithPrefix
80+ -- , prefixOf -- match any prefix of a given string
81+ -- , suffixOf -- match any suffix of a given string
82+ -- , infixOf -- match any substring of a given string
80 -- Second order parsers (parsers using parsers)
84 -- Second order parsers (parsers using parsers)
81 -- * Binary Combinators
85 -- * Binary Combinators
@@ -572,6 +576,36 @@ groupBy ::
572 (a -> a -> Bool) -> Fold m a b -> Parser m a b
576 (a -> a -> Bool) -> Fold m a b -> Parser m a b
573groupBy = undefined
577groupBy = undefined
579+-- XXX use an Unfold instead of a list?
580+-- XXX custom combinators for matching list, array and stream?
582+-- | Match the given sequence of elements using the given comparison function.
587+eqBy :: MonadThrow m => (a -> a -> Bool) -> [a] -> Parser m a ()
588+eqBy cmp str = Parser step initial extract
592+ initial = return str
594+ step [] _ = error "Bug: unreachable"
595+ step [x] a = return $
599+ "eqBy: failed, at the last element"
600+ step (x:xs) a = return $
604+ "eqBy: failed, yet to match " ++ show (length xs) ++ " elements"
606+ extract xs = throwM $ ParseError $
607+ "eqBy: end of input, yet to match " ++ show (length xs) ++ " elements"
575-------------------------------------------------------------------------------
609-------------------------------------------------------------------------------
576-- nested parsers
610-- nested parsers
577-------------------------------------------------------------------------------
611-------------------------------------------------------------------------------