bitwalker / combine

A parser combinator library for Elixir projects
MIT License
197 stars 19 forks source link

Added `bind` to allow composition of parsers. #47

Open diasbruno opened 4 years ago

diasbruno commented 4 years ago

Closes #45

bitwalker commented 2 years ago

Unless I'm mistaken, pipe already handles this kind of composition, but in an unrestricted fashion, i.e. you can compose many parsers and only invoke the transformation function if all of them succeed. Nothing prevents you from using pipe with just a single parser though as an equivalent to what bind does here.

I'm not opposed to merging this as-is, but I'm wondering if you think there is a benefit to having both functions if they essentially overlap 1:1 in functionality?

diasbruno commented 2 years ago

I didn't know pipe implemented this functionality. Maybe because bind is a common name for this, but if it does the job, we can close this.

Thanks!

diasbruno commented 2 years ago

I'll try to have a look on the docs and see if we add something there.

diasbruno commented 2 years ago

I looked at pipe and the only difference I can see is that it uses some arrays and a reverse...I don't know if it would be a good idea, but maybe we could implement pipe using bind and maybe remove the intermediary arrays of pipe. Any thoughts?