Movatterモバイル変換


[0]ホーム

URL:


base-4.16.3.0: Basic libraries
Copyright(C) 2011-2015 Edward Kmett
(C) 2010 Tony Morris Oliver Taylor Eelis van der Weegen
LicenseBSD-style (see the file LICENSE)
Maintainerlibraries@haskell.org
Stabilityprovisional
Portabilityportable
Safe HaskellTrustworthy
LanguageHaskell2010

Data.List.NonEmpty

Contents

Description

ANonEmpty list is one which always has at least one element, but is otherwise identical to the traditional list type in complexity and in terms of API. You will almost certainly want to import this modulequalified.

Since: base-4.9.0.0

Synopsis

The type of non-empty streams

dataNonEmpty aSource#

Non-empty (and non-strict) list type.

Since: base-4.9.0.0

Constructors

a:| [a]infixr 5 

Instances

Instances details
MonadFixNonEmptySource#

Since: base-4.9.0.0

Instance details

Defined inControl.Monad.Fix

Methods

mfix :: (a ->NonEmpty a) ->NonEmpty aSource#

MonadZipNonEmptySource#

Since: base-4.9.0.0

Instance details

Defined inControl.Monad.Zip

Methods

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

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

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

FoldableNonEmptySource#

Since: base-4.9.0.0

Instance details

Defined inData.Foldable

Methods

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

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

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

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

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

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

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

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

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

toList ::NonEmpty a -> [a]Source#

null ::NonEmpty a ->BoolSource#

length ::NonEmpty a ->IntSource#

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

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

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

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

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

Eq1NonEmptySource#

Since: base-4.10.0.0

Instance details

Defined inData.Functor.Classes

Methods

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

Ord1NonEmptySource#

Since: base-4.10.0.0

Instance details

Defined inData.Functor.Classes

Methods

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

Read1NonEmptySource#

Since: base-4.10.0.0

Instance details

Defined inData.Functor.Classes

Show1NonEmptySource#

Since: base-4.10.0.0

Instance details

Defined inData.Functor.Classes

Methods

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

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

TraversableNonEmptySource#

Since: base-4.9.0.0

Instance details

Defined inData.Traversable

Methods

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

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

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

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

ApplicativeNonEmptySource#

Since: base-4.9.0.0

Instance details

Defined inGHC.Base

FunctorNonEmptySource#

Since: base-4.9.0.0

Instance details

Defined inGHC.Base

Methods

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

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

MonadNonEmptySource#

Since: base-4.9.0.0

Instance details

Defined inGHC.Base

Generic1NonEmptySource# 
Instance details

Defined inGHC.Generics

Associated Types

typeRep1NonEmpty :: k ->TypeSource#

Methods

from1 ::forall (a :: k).NonEmpty a ->Rep1NonEmpty aSource#

to1 ::forall (a :: k).Rep1NonEmpty a ->NonEmpty aSource#

Data a =>Data (NonEmpty a)Source#

Since: base-4.9.0.0

Instance details

Defined inData.Data

Methods

gfoldl :: (forall d b.Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) ->NonEmpty a -> c (NonEmpty a)Source#

gunfold :: (forall b r.Data b => c (b -> r) -> c r) -> (forall r. r -> c r) ->Constr -> c (NonEmpty a)Source#

toConstr ::NonEmpty a ->ConstrSource#

dataTypeOf ::NonEmpty a ->DataTypeSource#

dataCast1 ::Typeable t => (forall d.Data d => c (t d)) ->Maybe (c (NonEmpty a))Source#

dataCast2 ::Typeable t => (forall d e. (Data d,Data e) => c (t d e)) ->Maybe (c (NonEmpty a))Source#

gmapT :: (forall b.Data b => b -> b) ->NonEmpty a ->NonEmpty aSource#

gmapQl :: (r -> r' -> r) -> r -> (forall d.Data d => d -> r') ->NonEmpty a -> rSource#

gmapQr ::forall r r'. (r' -> r -> r) -> r -> (forall d.Data d => d -> r') ->NonEmpty a -> rSource#

gmapQ :: (forall d.Data d => d -> u) ->NonEmpty a -> [u]Source#

gmapQi ::Int -> (forall d.Data d => d -> u) ->NonEmpty a -> uSource#

gmapM ::Monad m => (forall d.Data d => d -> m d) ->NonEmpty a -> m (NonEmpty a)Source#

gmapMp ::MonadPlus m => (forall d.Data d => d -> m d) ->NonEmpty a -> m (NonEmpty a)Source#

gmapMo ::MonadPlus m => (forall d.Data d => d -> m d) ->NonEmpty a -> m (NonEmpty a)Source#

Semigroup (NonEmpty a)Source#

Since: base-4.9.0.0

Instance details

Defined inGHC.Base

IsList (NonEmpty a)Source#

Since: base-4.9.0.0

Instance details

Defined inGHC.Exts

Associated Types

typeItem (NonEmpty a)Source#

Generic (NonEmpty a)Source# 
Instance details

Defined inGHC.Generics

Associated Types

typeRep (NonEmpty a) ::Type ->TypeSource#

Read a =>Read (NonEmpty a)Source#

Since: base-4.11.0.0

Instance details

Defined inGHC.Read

Show a =>Show (NonEmpty a)Source#

Since: base-4.11.0.0

Instance details

Defined inGHC.Show

Eq a =>Eq (NonEmpty a)Source#

Since: base-4.9.0.0

Instance details

Defined inGHC.Base

Ord a =>Ord (NonEmpty a)Source#

Since: base-4.9.0.0

Instance details

Defined inGHC.Base

typeRep1NonEmptySource#

Since: base-4.6.0.0

Instance details

Defined inGHC.Generics

typeItem (NonEmpty a)Source# 
Instance details

Defined inGHC.Exts

typeItem (NonEmpty a) = a
typeRep (NonEmpty a)Source#

Since: base-4.6.0.0

Instance details

Defined inGHC.Generics

Non-empty stream transformations

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

Map a function over aNonEmpty stream.

intersperse :: a ->NonEmpty a ->NonEmpty aSource#

'intersperse x xs' alternates elements of the list with copies ofx.

intersperse 0 (1 :| [2,3]) == 1 :| [0,2,0,3]

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

scanl is similar tofoldl, but returns a stream of successive reduced values from the left:

scanl f z [x1, x2, ...] == z :| [z `f` x1, (z `f` x1) `f` x2, ...]

Note that

last (scanl f z xs) == foldl f z xs.

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

scanr is the right-to-left dual ofscanl. Note that

head (scanr f z xs) == foldr f z xs.

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

scanl1 is a variant ofscanl that has no starting value argument:

scanl1 f [x1, x2, ...] == x1 :| [x1 `f` x2, x1 `f` (x2 `f` x3), ...]

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

scanr1 is a variant ofscanr that has no starting value argument.

transpose ::NonEmpty (NonEmpty a) ->NonEmpty (NonEmpty a)Source#

transpose forNonEmpty, behaves the same astranspose The rows/columns need not be the same length, in which case > transpose . transpose /= id

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

sortBy forNonEmpty, behaves the same assortBy

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

sortWith forNonEmpty, behaves the same as:

sortBy . comparing

Basic functions

length ::NonEmpty a ->IntSource#

Number of elements inNonEmpty list.

head ::NonEmpty a -> aSource#

Extract the first element of the stream.

tail ::NonEmpty a -> [a]Source#

Extract the possibly-empty tail of the stream.

last ::NonEmpty a -> aSource#

Extract the last element of the stream.

init ::NonEmpty a -> [a]Source#

Extract everything except the last element of the stream.

singleton :: a ->NonEmpty aSource#

Construct aNonEmpty list from a single element.

Since: base-4.15

(<|) :: a ->NonEmpty a ->NonEmpty ainfixr 5Source#

Prepend an element to the stream.

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

Synonym for<|.

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

uncons produces the first element of the stream, and a stream of the remaining elements, if any.

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

Theunfoldr function is analogous toData.List'sunfoldr operation.

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

Sort a stream.

reverse ::NonEmpty a ->NonEmpty aSource#

reverse a finite NonEmpty stream.

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

Theinits function takes a streamxs and returns all the finite prefixes ofxs.

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

Thetails function takes a streamxs and returns all the suffixes ofxs.

append ::NonEmpty a ->NonEmpty a ->NonEmpty aSource#

A monomorphic version of<> forNonEmpty.

>>>append (1 :| []) (2 :| [3])1 :| [2,3]

Since: base-4.16

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

Attach a list at the end of aNonEmpty.

>>>appendList (1 :| [2,3]) []1 :| [2,3]
>>>appendList (1 :| [2,3]) [4,5]1 :| [2,3,4,5]

Since: base-4.16

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

Attach a list at the beginning of aNonEmpty.

>>>prependList [] (1 :| [2,3])1 :| [2,3]
>>>prependList [negate 1, 0] (1 :| [2, 3])-1 :| [0,1,2,3]

Since: base-4.16

Building streams

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

iterate f x produces the infinite sequence of repeated applications off tox.

iterate f x = x :| [f x, f (f x), ..]

repeat :: a ->NonEmpty aSource#

repeat x returns a constant stream, where all elements are equal tox.

cycle ::NonEmpty a ->NonEmpty aSource#

cycle xs returns the infinite repetition ofxs:

cycle (1 :| [2,3]) = 1 :| [2,3,1,2,3,...]

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

Deprecated: Use unfoldr

unfold produces a new stream by repeatedly applying the unfolding function to the seed value to produce an element of typeb and a new seed value. When the unfolding function returnsNothing instead of a new seed value, the stream ends.

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

insert x xs insertsx into the last position inxs where it is still less than or equal to the next element. In particular, if the list is sorted beforehand, the result will also be sorted.

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

some1 x sequencesx one or more times.

Extracting sublists

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

take n xs returns the firstn elements ofxs.

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

drop n xs drops the firstn elements off the front of the sequencexs.

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

splitAt n xs returns a pair consisting of the prefix ofxs of lengthn and the remaining stream immediately following this prefix.

'splitAt' n xs == ('take' n xs, 'drop' n xs)xs == ys ++ zs where (ys, zs) = 'splitAt' n xs

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

takeWhile p xs returns the longest prefix of the streamxs for which the predicatep holds.

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

dropWhile p xs returns the suffix remaining aftertakeWhile p xs.

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

span p xs returns the longest prefix ofxs that satisfiesp, together with the remainder of the stream.

'span' p xs == ('takeWhile' p xs, 'dropWhile' p xs)xs == ys ++ zs where (ys, zs) = 'span' p xs

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

Thebreak p function is equivalent tospan (not . p).

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

filter p xs removes any elements fromxs that do not satisfyp.

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

Thepartition function takes a predicatep and a streamxs, and returns a pair of lists. The first list corresponds to the elements ofxs for whichp holds; the second corresponds to the elements ofxs for whichp does not hold.

'partition' p xs = ('filter' p xs, 'filter' (not . p) xs)

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

Thegroup function takes a stream and returns a list of streams such that flattening the resulting list is equal to the argument. Moreover, each stream in the resulting list contains only equal elements. For example, in list notation:

'group' $ 'cycle' "Mississippi"  = "M" : "i" : "ss" : "i" : "ss" : "i" : "pp" : "i" : "M" : "i" : ...

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

groupBy operates likegroup, but uses the provided equality predicate instead of==.

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

groupWith operates likegroup, but uses the provided projection when comparing for equality

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

groupAllWith operates likegroupWith, but sorts the list first so that each equivalence class has, at most, one list in the output

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

group1 operates likegroup, but uses the knowledge that its input is non-empty to produce guaranteed non-empty output.

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

groupBy1 is togroup1 asgroupBy is togroup.

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

groupWith1 is togroup1 asgroupWith is togroup

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

groupAllWith1 is togroupWith1 asgroupAllWith is togroupWith

Sublist predicates

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

TheisPrefixOf function returnsTrue if the first argument is a prefix of the second.

"Set" operations

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

Thenub function removes duplicate elements from a list. In particular, it keeps only the first occurrence of each element. (The namenub means 'essence'.) It is a special case ofnubBy, which allows the programmer to supply their own inequality test.

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

ThenubBy function behaves just likenub, except it uses a user-supplied equality predicate instead of the overloaded== function.

Indexing streams

(!!) ::NonEmpty a ->Int -> ainfixl 9Source#

xs !! n returns the element of the streamxs at indexn. Note that the head of the stream has index 0.

Beware: a negative or out-of-bounds index will cause an error.

Zipping and unzipping streams

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

Thezip function takes two streams and returns a stream of corresponding pairs.

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

ThezipWith function generalizeszip. Rather than tupling the elements, the elements are combined using the function passed as the first argument.

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

Theunzip function is the inverse of thezip function.

Converting to and from a list

fromList :: [a] ->NonEmpty aSource#

Converts a normal list to aNonEmpty stream.

Raises an error if given an empty list.

toList ::NonEmpty a -> [a]Source#

Convert a stream to a normal list efficiently.

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

nonEmpty efficiently turns a normal list into aNonEmpty stream, producingNothing if the input is empty.

xor ::NonEmptyBool ->BoolSource#

Compute n-ary logic exclusive OR operation onNonEmpty list.

Produced byHaddock version 2.26.0


[8]ページ先頭

©2009-2025 Movatter.jp