Module: list/inf

Methods

(static) cycle(as) → {List}

Return the infinite repetition of a List (i.e. the "identity" of infinite lists).
Haskell> cycle :: [a] -> [a]

Parameters:
Name Type Description
as List

A finite List

Source:
Returns:

A circular List, the original List infinitely repeated

Type
List
Example
const lst = list(1,2,3);
const c = cycle(lst);
take(9, c);              // => [1:2:3:1:2:3:1:2:3:[]]
index(c, 100);           // => 2

(static) iterate(f, x) → {List}

Return an infinite List of repeated applications of a function to a value.
Haskell> iterate :: (a -> a) -> a -> [a]

Parameters:
Name Type Description
f function

The function to apply

x *

The value to apply the function to

Source:
Returns:

An infinite List of repeated applications of f to x

Type
List
Example
const f = x => x * 2;
const lst = iterate(f, 1);
take(10, lst);             // => [1:2:4:8:16:32:64:128:256:512:[]]
index(lst, 10);            // => 1024

(static) listInf(start) → {List}

Generate an infinite List. Use listInfBy to supply your own step function.

Parameters:
Name Type Description
start *

The value with which to start the List

Source:
Returns:

An infinite List of consecutive values, incremented from start

Type
List

(static) listInfBy(start, step) → {List}

Generate an infinite List, incremented using a given step function.

Parameters:
Name Type Description
start *

The value with which to start the List

step function

A unary step function

Source:
Returns:

An infinite List of consecutive values, incremented from start

Type
List

(static) repeat(a) → {List}

Build an infinite List of identical values.
Haskell> repeat :: a -> [a]

Parameters:
Name Type Description
a *

The value to repeat

Source:
Returns:

The infinite List of repeated values

Type
List
Example
const lst = repeat(3);
take(10, lst);         // => [3:3:3:3:3:3:3:3:3:3:[]]
index(lst, 100);       // => 3

(static) replicate(n, x) → {List}

Return a List of a specified length in which every value is the same.
Haskell> replicate :: Int -> a -> [a]

Parameters:
Name Type Description
n number

The length of the List

x *

The value to replicate

Source:
Returns:

The List of values

Type
List
Example
replicate(10, 3); // => [3:3:3:3:3:3:3:3:3:3:[]]