haskell / haskell/core-libraries-committee

Add a right-handed `(:|)` to `Data.List.NonEmpty`

Open
#377 15 comments 0 reactions 0 assignees View on GitHub
awaits-impact-assessment awaits-MR
Dominant language
Haskell
Stars
109
Forks
20
PR merge metrics
No merged PRs in 30d

Description

Something like this:

```haskell
pattern (:>) :: [a] -> a -> NonEmpty a
pattern xs :> x <- (initLast -> (,) xs x) where
xs :> x = prependList xs $ singleton x

-- Perhaps unexported
initLast :: NonEmpty a -> ([a], a)
initLast (x :| xs) = case Data.List.unsnoc xs of
Nothing -> ([], x)
Just (ys, y) -> (x : ys, y)
```

or if `PatternSynonyms` are not acceptable in base, then a pair of functions comprising an `Iso' (NonEmpty a) ([a], a)`.

Contributor guide

No contributing guide indexed for this repository

Research direction

Review Data.List.NonEmpty and the proposed right-handed pattern (:) alongside PatternSynonyms and the alternative Iso' approach. Check how initLast would use Data.List.unsnoc, then determine which API shape is appropriate; done means an agreed addition or rejected alternative with corresponding library tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.