# \[ANN\] list1 -- Utilities for NonEmpty lists

**URL:** <https://discourse.haskell.org/t/ann-list1-utilities-for-nonempty-lists/10082>\
**Category:** Announcements\
**Created:** [August 2, 2024, 8:43pm UTC](https://discourse.haskell.org/t/ann-list1-utilities-for-nonempty-lists/10082 "2024-08-02T20:43:24Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![mixphix](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/mixphix/32/5629_2.png) [@mixphix](https://discourse.haskell.org/u/mixphix)\
**Post date:** [August 2, 2024, 8:43pm UTC](https://discourse.haskell.org/t/ann-list1-utilities-for-nonempty-lists/10082/1 "2024-08-02T20:43:24Z")

</div>

The [`list1` package](https://hackage.haskell.org/package/list1) offers an alternative interface to `Data.List.NonEmpty`. Most notably are the pattern synonyms

```hs
type List1 = NonEmpty

-- | Match a singleton 'List1'.
pattern Sole :: x -> List1 x
pattern Sole x = x :| []

-- | Match a 'List1' of length at least 2.
pattern (:||) :: x -> List1 x -> List1 x
pattern x :|| y <- (x :| (list1 -> Just y))
  where
    x :|| ~(y :| ys) = x :| (y : ys)

{-# COMPLETE Sole, (:||) #-}

-- | Isomorphic to '(:|)', but instead with a 'Maybe' 'List1'.
pattern (:?) :: x -> Maybe (List1 x) -> List1 x
pattern x :? y <- (x :| ~(list1 -> y))
  where
    x :? y = maybe (Sole x) (x :||) y

```

and extensive use of `Maybe` in the result types to facilitate working with possibly-empty results without leaving the `Maybe` monad. Documentation sold separately!

---

_[View the full topic](https://discourse.haskell.org/t/ann-list1-utilities-for-nonempty-lists/10082)._
