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

many1 and sepBy1 could return NonEmpty #150

Open
chris-martin opened this issue Feb 16, 2019 · 2 comments
Open

many1 and sepBy1 could return NonEmpty #150

chris-martin opened this issue Feb 16, 2019 · 2 comments

Comments

@chris-martin
Copy link
Contributor

It seems that these two functions in Data.Attoparsec.Combinator might have had NonEmpty a rather than [a] in their return types, since they are never supposed to yield an empty list.

many1  :: Alternative f => f a -> f [a]
sepBy1 :: Alternative f => f a -> f s -> f [a]

Perhaps we might introduce additional combinators?

manyNE  :: Alternative f => f a -> f (NonEmpty a)
sepByNE :: Alternative f => f a -> f s -> f (NonEmpty a)

The code I'm writing at the moment applies Data.List.last to the result of sepBy1, and I believe being able to instead apply Data.List.NonEmpty.last to the result of sepByNE would bring me happiness.

@hvr
Copy link
Member

hvr commented Feb 17, 2019

Hrm... by that argument you might also apply the same suggestion to base's Control.Applicative.some :-)

@chris-martin
Copy link
Contributor Author

I might!

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

No branches or pull requests

2 participants