Module: list/func

Members

(static, constant) emptyList

The empty list, or [] in Haskell (represented as [[]] in this library).
Haskell> [] :: [t]

Source:

Methods

(static) cons(x, xs) → {List}

Create a new List from a head and tail. As in Haskell, cons is based on the classic Lisp function of the same name.
Haskell> (:) :: a -> [a] -> [a]

Parameters:
Name Type Description
x *

Any value, the head of the new list

xs List

A List, the tail of the new list

Source:
Returns:

The new List, constructed from x and xs

Type
List
Example
const lst = list(4,5,6);
cons(3)(lst);            // => [3:4:5:6:[]]

(static) empty(t) → {boolean}

Test whether a Foldable structure (such as a List) is empty.
Haskell> null :: t a -> Bool

Parameters:
Name Type Description
t Object

The Foldable structure to test

Source:
Returns:

true if the structure is empty, false otherwise

Type
boolean
Example
empty(list(1,2,3)); // => false
empty(emptyList);   // => true

(static) fromArrayToList(arr) → {List}

Convert an array into a List.

Parameters:
Name Type Description
arr Array.<*>

An array to convert into a List

Source:
Returns:

A new List, the converted array

Type
List
Example
const arr = [1,2,3];
fromArrayToList(arr); // => [1:2:3:[]]

(static) fromListToArray(xs) → {Array}

Convert a List into an array.

Parameters:
Name Type Description
xs List

A List to convert into an array

Source:
Returns:

A new array, the converted List

Type
Array
Example
const lst = list(1,2,3);
fromListToArray(lst);    // => [1,2,3]

(static) fromListToString(xs) → {string}

Convert a List into a string.

Parameters:
Name Type Description
xs List

A List to convert into a string

Source:
Returns:

A new string, the converted List

Type
string
Example
const str = list('a','b','c');
fromListToString(str);         // => "abc"

(static) fromStringToList(str) → {List}

Convert a string into a List.

Parameters:
Name Type Description
str string

A string to convert into a List

Source:
Returns:

A new List, the converted string

Type
List
Example
const str = `abc`;
fromStringToList(str); // => [abc]

(static) head(xs) → {*}

Extract the first element of a List.
Haskell> head :: [a] -> a

Parameters:
Name Type Description
xs List

A List

Source:
Returns:

The head of the List

Type
*
Example
const lst = list(1,2,3);
head(lst);               // => 1

(static) init(xs) → {List}

Return all the elements of a List except the last one.
Haskell> tail :: [a] -> [a]

Parameters:
Name Type Description
xs List

A List

Source:
Returns:

A new List, without the original list's last element

Type
List
Example
const lst = list(1,2,3);
init(lst);               // => [1:2:[]]

(static) isEmpty(xs) → {boolean}

Check whether a List is empty. Returns true if the List is empty or false if it is non-empty. Throws a type error, otherwise.

Parameters:
Name Type Description
xs *

A List

Source:
Returns:

true if the List is empty, false if it is non-empty

Type
boolean
Example
isEmpty([]);              // => true
isEmpty([[]]);            // => false
isEmpty(emptyList);       // => true
isEmpty(list(emptyList)); // => false

(static) isList(a) → {boolean}

Determine whether a given object is a List.

Parameters:
Name Type Description
a *

Any object

Source:
Returns:

true if the object is a List and false otherwise

Type
boolean

(static) last(xs) → {*}

Extract the last element of a List.
Haskell> last :: [a] -> a

Parameters:
Name Type Description
xs List

A List

Source:
Returns:

The last element of the List

Type
*
Example
const lst = list(1,2,3);
last(lst);               // => 3

(static) length(xs) → {number}

Return the length of a List. In the future, this function should work on all Foldable structures.
Haskell> length :: Foldable t => t a -> Int

Parameters:
Name Type Description
xs List

A List

Source:
Returns:

The length of the List

Type
number
Example
const lst = list(1,2,3);
length(lst);             // => 3

(static) list(…as) → {List}

Create a new List from a series of zero or more values.

Parameters:
Name Type Attributes Description
as * <repeatable>

Values to put into a new List

Source:
Returns:

The new List

Type
List
Example
list(1,2,3); // => [1:2:3:[]]

(static) listAppend(xs, ys) → {List}

Append one List to another.
Haskell> (++) :: [a] -> [a] -> [a]

Parameters:
Name Type Description
xs List

A List

ys List

A List

Source:
Returns:

A new List, the result of appending xs to ys

Type
List
Example
const lst1 = list(1,2,3);
const lst2 = list(4,5,6);
listAppend(lst1, lst2);   // => [1:2:3:4:5:6:[]]

(static) listFilter(start, end, filtopt) → {List}

Build a List from a range of enumerated values, and apply a filter to each one. This function is a shortcut for listRange that simply applies a filter with the default function x = x + 1.

Parameters:
Name Type Attributes Description
start *

The beginning of the range (inclusive)

end *

The end of the range (exclusive)

filt function <optional>

An optional filter (returning boolean) to test whether to add each value to the List

Source:
Returns:

A new List of filtered values

Type
List
Example
const f = x => x + 5;
const evens = x => even(x);
listFilter(1, 30, evens);   // => [2:4:6:8:10:12:14:16:18:20:22:24:26:28:[]]

(static) listRange(start, end, fopt, filtopt) → {List}

Build a List from a range of values. Currently, this only works with numbers. The equivalent is achieved in Haskell using list comprehensions.

Parameters:
Name Type Attributes Default Description
start *

The beginning of the range (inclusive)

end *

The end of the range (exclusive)

f function <optional>
(x => x + 1)

The function to apply iteratively to each value

filt function <optional>

An optional filter (returning boolean) to test whether to add each value to the List

Source:
Returns:

The new List

Type
List
Example
const f = x => x + 5;
const evens = x => even(x);
listRange(0, 100, f);        // => [0:5:10:15:20:25:30:35:40:45:50:55:60:65:70:75:80:85:90:95:[]]
listRange(0, 100, f, evens); // => [0:10:20:30:40:50:60:70:80:90:[]]

(static) listRangeLazy(start, end) → {List}

Build a List from a range of values using lazy evaluation (i.e. each successive value is only computed on demand, making infinite lists feasible). To supply your own function for determining the increment, use listRangeLazyBy.

Parameters:
Name Type Description
start *

The starting value

end *

The end value

Source:
Returns:

A List that will be evaluated lazily

Type
List

(static) listRangeLazyBy(start, end, step) → {List}

Build a List from a range of values using lazy evaluation and incrementing it using a given step function.

Parameters:
Name Type Description
start *

The starting value

end *

The end value

step function

The increment function

Source:
Returns:

A List that will be evaluated lazily

Type
List

(static) tail(xs) → {List}

Extract the elements after the head of a List.
Haskell> tail :: [a] -> [a]

Parameters:
Name Type Description
xs List

A List

Source:
Returns:

The tail of the List

Type
List
Example
const lst = list(1,2,3);
tail(lst);               // => [2:3:[]]

(static) uncons(xs) → {Maybe}

Decompose a List into its head and tail. If the list is empty, returns Nothing. If the list is non-empty, returns Just (x, xs), where x is the head of the List and xs its tail.
Haskell> uncons :: [a] -> Maybe (a, [a])

Parameters:
Name Type Description
xs List

The List to decompose

Source:
Returns:

The decomposed List wrapped in a Just, or Nothing if the list is empty

Type
Maybe
Example
const lst = list(1,2,3);
uncons(lst);             // => Just (1,[2:3:[]])