extra-data-yj-0.1.0.0: Additional data types
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.List.Infinite

Synopsis

Definition

data Infinite a Source #

Constructors

a :~ (Infinite a) infixr 5 

Instances

Instances details
Foldable Infinite Source # 
Instance details

Defined in Data.List.Infinite

Methods

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

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

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

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

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

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

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

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

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

toList :: Infinite a -> [a] #

null :: Infinite a -> Bool #

length :: Infinite a -> Int #

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

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

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

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

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

Applicative Infinite Source # 
Instance details

Defined in Data.List.Infinite

Methods

pure :: a -> Infinite a #

(<*>) :: Infinite (a -> b) -> Infinite a -> Infinite b #

liftA2 :: (a -> b -> c) -> Infinite a -> Infinite b -> Infinite c #

(*>) :: Infinite a -> Infinite b -> Infinite b #

(<*) :: Infinite a -> Infinite b -> Infinite a #

Functor Infinite Source # 
Instance details

Defined in Data.List.Infinite

Methods

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

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

data NonEmpty a #

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

Since: base-4.9.0.0

Constructors

a :| [a] infixr 5 

Instances

Instances details
Foldable NonEmpty

Since: base-4.9.0.0

Instance details

Defined in 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

Since: base-4.9.0.0

Instance details

Defined in 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) #

Applicative NonEmpty

Since: base-4.9.0.0

Instance details

Defined in GHC.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

Since: base-4.9.0.0

Instance details

Defined in GHC.Base

Methods

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

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

Monad NonEmpty

Since: base-4.9.0.0

Instance details

Defined in GHC.Base

Methods

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

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

return :: a -> NonEmpty a #

Semigroup (NonEmpty a)

Since: base-4.9.0.0

Instance details

Defined in GHC.Base

Methods

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

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

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

Read a => Read (NonEmpty a)

Since: base-4.11.0.0

Instance details

Defined in GHC.Read

Show a => Show (NonEmpty a)

Since: base-4.11.0.0

Instance details

Defined in GHC.Show

Methods

showsPrec :: Int -> NonEmpty a -> ShowS #

show :: NonEmpty a -> String #

showList :: [NonEmpty a] -> ShowS #

Eq a => Eq (NonEmpty a)

Since: base-4.9.0.0

Instance details

Defined in GHC.Base

Methods

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

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

Ord a => Ord (NonEmpty a)

Since: base-4.9.0.0

Instance details

Defined in GHC.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 #

Basic functions

append :: [a] -> Infinite a -> Infinite a Source #

List transformations

intercalate :: [a] -> Infinite [a] -> Infinite a Source #

Reducing lists (folds)

foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b #

Right-associative fold of a structure, lazy in the accumulator.

In the case of lists, foldr, when applied to a binary operator, a starting value (typically the right-identity of the operator), and a list, reduces the list using the binary operator, from right to left:

foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)

Note that since the head of the resulting expression is produced by an application of the operator to the first element of the list, given an operator lazy in its right argument, foldr can produce a terminating expression from an unbounded list.

For a general Foldable structure this should be semantically identical to,

foldr f z = foldr f z . toList

Examples

Expand

Basic usage:

>>> foldr (||) False [False, True, False]
True
>>> foldr (||) False []
False
>>> foldr (\c acc -> acc ++ [c]) "foo" ['a', 'b', 'c', 'd']
"foodcba"
Infinite structures

⚠️ Applying foldr to infinite structures usually doesn't terminate.

It may still terminate under one of the following conditions:

  • the folding function is short-circuiting
  • the folding function is lazy on its second argument
Short-circuiting

(||) short-circuits on True values, so the following terminates because there is a True value finitely far from the left side:

>>> foldr (||) False (True : repeat False)
True

But the following doesn't terminate:

>>> foldr (||) False (repeat False ++ [True])
* Hangs forever *
Laziness in the second argument

Applying foldr to infinite structures terminates when the operator is lazy in its second argument (the initial accumulator is never used in this case, and so could be left undefined, but [] is more clear):

>>> take 5 $ foldr (\i acc -> i : fmap (+3) acc) [] (repeat 1)
[1,4,7,10,13]

Scans

scanl :: (b -> a -> b) -> b -> Infinite a -> Infinite b Source #

scanl' :: (b -> a -> b) -> b -> Infinite a -> Infinite b Source #

Infinite lists

iterate :: (a -> a) -> a -> Infinite a Source #

iterate' :: (a -> a) -> a -> Infinite a Source #

unfoldr :: (b -> (a, b)) -> b -> Infinite a Source #

Extracting sublits

take :: Integral i => i -> Infinite a -> [a] Source #

drop :: Integral i => i -> Infinite a -> Infinite a Source #

splitAt :: Integral i => i -> Infinite a -> ([a], Infinite a) Source #

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

group :: Eq a => Infinite a -> Infinite [a] Source #

groupBy :: (a -> a -> Bool) -> Infinite a -> Infinite [a] Source #

Predicates

isPrefixOf :: Eq a => [a] -> Infinite a -> Bool Source #

Searching

partition :: (a -> Bool) -> Infinite a -> (Infinite a, Infinite a) Source #

Indexing lists

index :: Integral i => Infinite a -> i -> a infixl 9 Source #

Zipping and unzipping lists

zipWith :: (a -> b -> c) -> Infinite a -> Infinite b -> Infinite c Source #

unzip :: Infinite (a, b) -> (Infinite a, Infinite b) Source #

Set operations

delete :: Eq a => a -> Infinite a -> Infinite a Source #

(\\) :: Eq a => Infinite a -> [a] -> Infinite a Source #

Ordered lists

insert :: Ord a => a -> Infinite a -> Infinite a Source #

insertBy :: (a -> a -> Ordering) -> a -> Infinite a -> Infinite a Source #