Safe Haskell | Safe-Inferred |
---|---|

Language | Haskell2010 |

Extra functions for working with `NonEmpty`

lists. The package
also exports the existing Data.List.NonEmpty functions.

## Synopsis

- module Data.List.NonEmpty
- (|:) :: [a] -> a -> NonEmpty a
- (|>) :: NonEmpty a -> a -> NonEmpty a
- snoc :: NonEmpty a -> a -> NonEmpty a
- appendl :: NonEmpty a -> [a] -> NonEmpty a
- appendr :: [a] -> NonEmpty a -> NonEmpty a
- sortOn :: Ord b => (a -> b) -> NonEmpty a -> NonEmpty a
- union :: Eq a => NonEmpty a -> NonEmpty a -> NonEmpty a
- unionBy :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty a -> NonEmpty a
- nubOrd :: Ord a => NonEmpty a -> NonEmpty a
- nubOrdBy :: (a -> a -> Ordering) -> NonEmpty a -> NonEmpty a
- nubOrdOn :: Ord b => (a -> b) -> NonEmpty a -> NonEmpty a
- maximum1 :: Ord a => NonEmpty a -> a
- minimum1 :: Ord a => NonEmpty a -> a
- maximumBy1 :: (a -> a -> Ordering) -> NonEmpty a -> a
- minimumBy1 :: (a -> a -> Ordering) -> NonEmpty a -> a
- maximumOn1 :: Ord b => (a -> b) -> NonEmpty a -> a
- minimumOn1 :: Ord b => (a -> b) -> NonEmpty a -> a

# Documentation

module Data.List.NonEmpty

(|:) :: [a] -> a -> NonEmpty a infixl 5 Source #

*O(n)*. Append an element to a list.

[1,2,3] |: 4 |> 5 == 1 :| [2,3,4,5]

(|>) :: NonEmpty a -> a -> NonEmpty a infixl 5 Source #

*O(n)*. Append an element to a non-empty list.

(1 :| [2,3]) |> 4 |> 5 == 1 :| [2,3,4,5]

appendl :: NonEmpty a -> [a] -> NonEmpty a Source #

Append a list to a non-empty list.

appendl (1 :| [2,3]) [4,5] == 1 :| [2,3,4,5]

appendr :: [a] -> NonEmpty a -> NonEmpty a Source #

Append a non-empty list to a list.

appendr [1,2,3] (4 :| [5]) == 1 :| [2,3,4,5]

sortOn :: Ord b => (a -> b) -> NonEmpty a -> NonEmpty a Source #

Sort by comparing the results of a function applied to each element. The sort is stable, and the function is evaluated only once for each element.

union :: Eq a => NonEmpty a -> NonEmpty a -> NonEmpty a Source #

Return the union of two non-empty lists. Duplicates, and elements of the first list, are removed from the the second list, but if the first list contains duplicates, so will the result.

(1 :| [3, 5, 3]) `union` (4 :| [5, 3, 5, 2]) == 1 :| [3, 5, 3, 4, 2]

unionBy :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty a -> NonEmpty a Source #

The non-overloaded version of `union`

.

maximumBy1 :: (a -> a -> Ordering) -> NonEmpty a -> a Source #

The largest element of a non-empty list with respect to the given comparison function.

minimumBy1 :: (a -> a -> Ordering) -> NonEmpty a -> a Source #

The least element of a non-empty list with respect to the given comparison function.