extra-1.7.6: Extra functions I use.

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.

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

nubOrd for NonEmpty. Behaves the same as nubOrd.

Data.List.NonEmpty.Extra.nubOrd (1 :| [2, 3, 3, 4, 1, 2]) == 1 :| [2, 3, 4]
\xs -> Data.List.NonEmpty.Extra.nubOrd xs == Data.List.NonEmpty.Extra.nub xs

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

nubOrdBy for NonEmpty. Behaves the same as nubOrdBy.

Data.List.NonEmpty.Extra.nubOrdBy (compare on Data.List.length) ("a" :| ["test","of","this"]) == "a" :| ["test","of"]

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

nubOrdOn for NonEmpty. Behaves the same as nubOrdOn.

Data.List.NonEmpty.Extra.nubOrdOn Data.List.length ("a" :| ["test","of","this"]) == "a" :| ["test","of"]

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.