Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manyMonoid? #220

Open
jamesdbrock opened this issue Dec 10, 2022 · 0 comments
Open

manyMonoid? #220

jamesdbrock opened this issue Dec 10, 2022 · 0 comments

Comments

@jamesdbrock
Copy link
Member

https://discord.com/channels/864614189094928394/865401680497737758/1050733797278228500

@artemisSystem
is there a combinator in parsing that works like many but accumulates in an arbitrary monoid?

like this:

manyMonoid   s a. Monoid a  Parser s a  Parser s a
manyMonoid = many >>> map fold
manyMonoid p = tailRecM go empty
where
go accum = alt
  do
    x <- p
    pure (Loop (accum <> x))
  do
    pure (Done accum)

See also https://pursuit.purescript.org/packages/purescript-arrays/7.1.0/docs/Data.Array#v:foldRecM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant