haskell / haskell/attoparsec

many1 and sepBy1 could return NonEmpty

Open
#150 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Haskell
Stars
531
Forks
98
PR merge metrics
No merged PRs in 30d

Description

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.

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

Perhaps we might introduce additional combinators?

```haskell
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.