base-compat-0.14.1: A compatibility layer for base
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.List.NonEmpty.Compat

Description

This backports the modern Data.Semigroup interface back to base-4.9/GHC 8.0.

Synopsis

The type of non-empty streams

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

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

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

Non-empty stream transformations

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

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

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

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

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

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

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

Basic functions

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

head :: NonEmpty a -> a #

tail :: NonEmpty a -> [a] #

last :: NonEmpty a -> a #

init :: NonEmpty a -> [a] #

singleton :: a -> NonEmpty a #

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

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

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

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

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

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

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

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

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

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

Building streams

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

repeat :: a -> NonEmpty a #

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

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

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

Extracting sublists

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Sublist predicates

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

"Set" operations

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

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

Indexing streams

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

Zipping and unzipping streams

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

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

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

Converting to and from a list

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

toList :: NonEmpty a -> [a] #

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