parser-combinators icon indicating copy to clipboard operation
parser-combinators copied to clipboard

[Proposal] Adding (back ?) chainl

Open Luc-Saccoccio opened this issue 2 years ago • 1 comments

Hi !

Is it possible to add the chainl, chainl1, chainr, chainr1 combinators ? Although Control.Monad.Combinators.Expr does exists, it feels overkill to use when there's only one layer to the chain; and I don't really understand why it was removed from megaparsec

The implementation would be pretty straightforward :

chainl1 parser op = parser >>= rest
  where rest x = do { f <- op; y <- parser; rest (f x y) } <|> return x

chainl parser op x = chainl1 parser op <|> return x

and so on...

Thanks in advance :) !

Luc-Saccoccio avatar Sep 24 '23 16:09 Luc-Saccoccio

Would you like to open a PR?

mrkkrp avatar Sep 26 '23 07:09 mrkkrp