extra-1.7.14: Extra functions I use.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.List.NonEmpty.Extra

Description

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
- (!?) :: NonEmpty a -> Int -> Maybe 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
- foldl1' :: (a -> a -> a) -> NonEmpty a -> a
- repeatedly :: (NonEmpty a -> (b, [a])) -> NonEmpty a -> NonEmpty b

# 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]

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

Synonym for `|>`.

(!?) :: NonEmpty a -> Int -> Maybe a infixl 9 Source #

A total variant of the list index function `(!?)`.

    (2 :| [3,4]) !? 1    == Just 3
    (2 :| [3,4]) !? (-1) == Nothing
    (1 :| [])    !? 1    == Nothing

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.

foldl1' :: (a -> a -> a) -> NonEmpty a -> a Source #

A strict variant of variant `foldl1`

repeatedly :: (NonEmpty a -> (b, [a])) -> NonEmpty a -> NonEmpty b Source #

Apply some operation repeatedly, producing an element of output and the remainder of the list.