extra-1.6.18: Extra functions I use.

Safe HaskellSafe
LanguageHaskell2010

Data.List.NonEmpty.Extra

Description

Extra functions for working with NonEmpty lists. The package also exports the existing Data.List.NonEmpty functions.

Synopsis

Documentation

(|:) :: [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]

snoc :: NonEmpty a -> a -> NonEmpty a Source #

Synonym for |>.

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.

maximum1 :: Ord a => NonEmpty a -> a Source #

The largest element of a non-empty list.

minimum1 :: Ord a => NonEmpty a -> a Source #

The least element of a non-empty list.

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.

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

A version of maximum1 where the comparison is done on some extracted value.

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

A version of minimum1 where the comparison is done on some extracted value.