haskell / attoparsec

A fast Haskell library for parsing ByteStrings
http://hackage.haskell.org/package/attoparsec
Other
514 stars 93 forks source link

many1 and sepBy1 could return NonEmpty #150

Open chris-martin opened 5 years ago

chris-martin commented 5 years ago

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 commented 5 years ago

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

chris-martin commented 5 years ago

I might!