extra-1.8: Extra functions I use.
Safe HaskellSafe-Inferred
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

group :: (Foldable f, Eq a) => f a -> [NonEmpty a] #

cons :: a -> NonEmpty a -> NonEmpty a #

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

data NonEmpty a #

Constructors

a :| [a] 

Instances

Instances details
MonadZip NonEmpty 
Instance details

Defined in Control.Monad.Zip

Methods

mzip :: NonEmpty a -> NonEmpty b -> NonEmpty (a, b)

mzipWith :: (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c

munzip :: NonEmpty (a, b) -> (NonEmpty a, NonEmpty b)

Foldable1 NonEmpty 
Instance details

Defined in Data.Foldable1

Methods

fold1 :: Semigroup m => NonEmpty m -> m

foldMap1 :: Semigroup m => (a -> m) -> NonEmpty a -> m

foldMap1' :: Semigroup m => (a -> m) -> NonEmpty a -> m

toNonEmpty :: NonEmpty a -> NonEmpty a

maximum :: Ord a => NonEmpty a -> a

minimum :: Ord a => NonEmpty a -> a

head :: NonEmpty a -> a

last :: NonEmpty a -> a

foldrMap1 :: (a -> b) -> (a -> b -> b) -> NonEmpty a -> b

foldlMap1' :: (a -> b) -> (b -> a -> b) -> NonEmpty a -> b

foldlMap1 :: (a -> b) -> (b -> a -> b) -> NonEmpty a -> b

foldrMap1' :: (a -> b) -> (a -> b -> b) -> NonEmpty a -> b

Eq1 NonEmpty 
Instance details

Defined in Data.Functor.Classes

Methods

liftEq :: (a -> b -> Bool) -> NonEmpty a -> NonEmpty b -> Bool

Ord1 NonEmpty 
Instance details

Defined in Data.Functor.Classes

Methods

liftCompare :: (a -> b -> Ordering) -> NonEmpty a -> NonEmpty b -> Ordering

Read1 NonEmpty 
Instance details

Defined in Data.Functor.Classes

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (NonEmpty a)

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [NonEmpty a]

liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (NonEmpty a)

liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [NonEmpty a]

Show1 NonEmpty 
Instance details

Defined in Data.Functor.Classes

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> NonEmpty a -> ShowS

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [NonEmpty a] -> ShowS

NFData1 NonEmpty 
Instance details

Defined in Control.DeepSeq

Methods

liftRnf :: (a -> ()) -> NonEmpty a -> ()

Applicative NonEmpty 
Instance details

Defined in GHC.Internal.Base

Methods

pure :: a -> NonEmpty a

(<*>) :: NonEmpty (a -> b) -> NonEmpty a -> NonEmpty b

liftA2 :: (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c

(*>) :: NonEmpty a -> NonEmpty b -> NonEmpty b

(<*) :: NonEmpty a -> NonEmpty b -> NonEmpty a

Functor NonEmpty 
Instance details

Defined in GHC.Internal.Base

Methods

fmap :: (a -> b) -> NonEmpty a -> NonEmpty b #

(<$) :: a -> NonEmpty b -> NonEmpty a #

Monad NonEmpty 
Instance details

Defined in GHC.Internal.Base

Methods

(>>=) :: NonEmpty a -> (a -> NonEmpty b) -> NonEmpty b #

(>>) :: NonEmpty a -> NonEmpty b -> NonEmpty b #

return :: a -> NonEmpty a #

Foldable NonEmpty 
Instance details

Defined in GHC.Internal.Data.Foldable

Methods

fold :: Monoid m => NonEmpty m -> m #

foldMap :: Monoid m => (a -> m) -> NonEmpty a -> m #

foldMap' :: Monoid m => (a -> m) -> NonEmpty a -> m #

foldr :: (a -> b -> b) -> b -> NonEmpty a -> b #

foldr' :: (a -> b -> b) -> b -> NonEmpty a -> b #

foldl :: (b -> a -> b) -> b -> NonEmpty a -> b #

foldl' :: (b -> a -> b) -> b -> NonEmpty a -> b #

foldr1 :: (a -> a -> a) -> NonEmpty a -> a #

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

toList :: NonEmpty a -> [a] #

null :: NonEmpty a -> Bool #

length :: NonEmpty a -> Int #

elem :: Eq a => a -> NonEmpty a -> Bool #

maximum :: Ord a => NonEmpty a -> a #

minimum :: Ord a => NonEmpty a -> a #

sum :: Num a => NonEmpty a -> a #

product :: Num a => NonEmpty a -> a #

Traversable NonEmpty 
Instance details

Defined in GHC.Internal.Data.Traversable

Methods

traverse :: Applicative f => (a -> f b) -> NonEmpty a -> f (NonEmpty b)

sequenceA :: Applicative f => NonEmpty (f a) -> f (NonEmpty a)

mapM :: Monad m => (a -> m b) -> NonEmpty a -> m (NonEmpty b) #

sequence :: Monad m => NonEmpty (m a) -> m (NonEmpty a) #

Generic1 NonEmpty 
Instance details

Defined in GHC.Internal.Generics

Associated Types

type Rep1 NonEmpty 
Instance details

Defined in GHC.Internal.Generics

type Rep1 NonEmpty = D1 ('MetaData "NonEmpty" "GHC.Internal.Base" "ghc-internal" 'False) (C1 ('MetaCons ":|" ('InfixI 'RightAssociative 5) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1 :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 [])))

Methods

from1 :: NonEmpty a -> Rep1 NonEmpty a

to1 :: Rep1 NonEmpty a -> NonEmpty a

Lift a => Lift (NonEmpty a :: Type) 
Instance details

Defined in Language.Haskell.TH.Syntax

Methods

lift :: Quote m => NonEmpty a -> m Exp

liftTyped :: forall (m :: Type -> Type). Quote m => NonEmpty a -> Code m (NonEmpty a)

NFData a => NFData (NonEmpty a) 
Instance details

Defined in Control.DeepSeq

Methods

rnf :: NonEmpty a -> ()

Semigroup (NonEmpty a) 
Instance details

Defined in GHC.Internal.Base

Methods

(<>) :: NonEmpty a -> NonEmpty a -> NonEmpty a #

sconcat :: NonEmpty (NonEmpty a) -> NonEmpty a

stimes :: Integral b => b -> NonEmpty a -> NonEmpty a

Generic (NonEmpty a) 
Instance details

Defined in GHC.Internal.Generics

Associated Types

type Rep (NonEmpty a) 
Instance details

Defined in GHC.Internal.Generics

type Rep (NonEmpty a) = D1 ('MetaData "NonEmpty" "GHC.Internal.Base" "ghc-internal" 'False) (C1 ('MetaCons ":|" ('InfixI 'RightAssociative 5) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a])))

Methods

from :: NonEmpty a -> Rep (NonEmpty a) x

to :: Rep (NonEmpty a) x -> NonEmpty a

IsList (NonEmpty a) 
Instance details

Defined in GHC.Internal.IsList

Associated Types

type Item (NonEmpty a) 
Instance details

Defined in GHC.Internal.IsList

type Item (NonEmpty a) = a

Methods

fromList :: [Item (NonEmpty a)] -> NonEmpty a

fromListN :: Int -> [Item (NonEmpty a)] -> NonEmpty a

toList :: NonEmpty a -> [Item (NonEmpty a)]

Read a => Read (NonEmpty a) 
Instance details

Defined in GHC.Internal.Read

Show a => Show (NonEmpty a) 
Instance details

Defined in GHC.Internal.Show

Methods

showsPrec :: Int -> NonEmpty a -> ShowS

show :: NonEmpty a -> String

showList :: [NonEmpty a] -> ShowS

Eq a => Eq (NonEmpty a) 
Instance details

Defined in GHC.Internal.Base

Methods

(==) :: NonEmpty a -> NonEmpty a -> Bool

(/=) :: NonEmpty a -> NonEmpty a -> Bool

Ord a => Ord (NonEmpty a) 
Instance details

Defined in GHC.Internal.Base

Methods

compare :: NonEmpty a -> NonEmpty a -> Ordering

(<) :: NonEmpty a -> NonEmpty a -> Bool

(<=) :: NonEmpty a -> NonEmpty a -> Bool

(>) :: NonEmpty a -> NonEmpty a -> Bool

(>=) :: NonEmpty a -> NonEmpty a -> Bool

max :: NonEmpty a -> NonEmpty a -> NonEmpty a

min :: NonEmpty a -> NonEmpty a -> NonEmpty a

type Rep1 NonEmpty 
Instance details

Defined in GHC.Internal.Generics

type Rep1 NonEmpty = D1 ('MetaData "NonEmpty" "GHC.Internal.Base" "ghc-internal" 'False) (C1 ('MetaCons ":|" ('InfixI 'RightAssociative 5) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1 :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 [])))
type Rep (NonEmpty a) 
Instance details

Defined in GHC.Internal.Generics

type Rep (NonEmpty a) = D1 ('MetaData "NonEmpty" "GHC.Internal.Base" "ghc-internal" 'False) (C1 ('MetaCons ":|" ('InfixI 'RightAssociative 5) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a])))
type Item (NonEmpty a) 
Instance details

Defined in GHC.Internal.IsList

type Item (NonEmpty a) = a

(!!) :: HasCallStack => NonEmpty a -> Int -> a #

break :: (a -> Bool) -> NonEmpty a -> ([a], [a]) #

drop :: Int -> NonEmpty a -> [a] #

dropWhile :: (a -> Bool) -> NonEmpty a -> [a] #

head :: NonEmpty a -> a #

init :: NonEmpty a -> [a] #

iterate :: (a -> a) -> a -> NonEmpty a #

last :: NonEmpty a -> a #

repeat :: a -> NonEmpty a #

scanl :: Foldable f => (b -> a -> b) -> b -> f a -> NonEmpty b #

scanl1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a #

scanr :: Foldable f => (a -> b -> b) -> b -> f a -> NonEmpty b #

scanr1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a #

span :: (a -> Bool) -> NonEmpty a -> ([a], [a]) #

splitAt :: Int -> NonEmpty a -> ([a], [a]) #

tail :: NonEmpty a -> [a] #

take :: Int -> NonEmpty a -> [a] #

takeWhile :: (a -> Bool) -> NonEmpty a -> [a] #

unzip :: Functor f => f (a, b) -> (f a, f b) #

zipWith :: (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c #

length :: NonEmpty a -> Int #

map :: (a -> b) -> NonEmpty a -> NonEmpty b #

zip :: NonEmpty a -> NonEmpty b -> NonEmpty (a, b) #

filter :: (a -> Bool) -> NonEmpty a -> [a] #

xor :: NonEmpty Bool -> Bool #

sort :: Ord a => NonEmpty a -> NonEmpty a #

groupBy :: Foldable f => (a -> a -> Bool) -> f a -> [NonEmpty a] #

nubBy :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty a #

sortBy :: (a -> a -> Ordering) -> NonEmpty a -> NonEmpty a #

isPrefixOf :: Eq a => [a] -> NonEmpty a -> Bool #

toList :: NonEmpty a -> [a] #

inits :: Foldable f => f a -> NonEmpty [a] #

insert :: (Foldable f, Ord a) => a -> f a -> NonEmpty a #

nub :: Eq a => NonEmpty a -> NonEmpty a #

partition :: (a -> Bool) -> NonEmpty a -> ([a], [a]) #

permutations :: [a] -> NonEmpty [a] #

singleton :: a -> NonEmpty a #

tails :: Foldable f => f a -> NonEmpty [a] #

unfoldr :: (a -> (b, Maybe a)) -> a -> NonEmpty b #

uncons :: NonEmpty a -> (a, Maybe (NonEmpty a)) #

(<|) :: a -> NonEmpty a -> NonEmpty a #

unfold :: (a -> (b, Maybe a)) -> a -> NonEmpty b #

appendList :: NonEmpty a -> [a] -> NonEmpty a #

fromList :: HasCallStack => [a] -> NonEmpty a #

group1 :: Eq a => NonEmpty a -> NonEmpty (NonEmpty a) #

groupAllWith :: Ord b => (a -> b) -> [a] -> [NonEmpty a] #

groupAllWith1 :: Ord b => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a) #

groupBy1 :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty (NonEmpty a) #

groupWith :: (Foldable f, Eq b) => (a -> b) -> f a -> [NonEmpty a] #

groupWith1 :: Eq b => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a) #

nonEmpty :: [a] -> Maybe (NonEmpty a) #

prependList :: [a] -> NonEmpty a -> NonEmpty a #

some1 :: Alternative f => f a -> f (NonEmpty a) #

sortWith :: Ord o => (a -> o) -> NonEmpty a -> NonEmpty a #

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

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.

compareLength :: NonEmpty a -> Int -> Ordering Source #

Use compareLength xs n as a safer and faster alternative to compare (length xs) n. Similarly, it's better to write compareLength xs 10 == LT instead of length xs < 10.

While length would force and traverse the entire spine of xs (which could even diverge if xs is infinite), compareLength traverses at most n elements to determine its result.

>>> compareLength ('a' :| []) 1
EQ
>>> compareLength ('a' :| ['b']) 3
LT
>>> compareLength (0 :| [1..]) 100
GT
>>> compareLength undefined 0
GT
>>> compareLength ('a' :| 'b' : undefined) 1
GT

Since: 4.21.0.0