Module: list/set

Methods

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

Non-associative list difference: remove the first occurrence of each value of a List in turn from another List. Use deleteFirstsBy to supply your own equality function.
Haskell> (\\) :: Eq a => [a] -> [a] -> [a]

Parameters:
Name Type Description
xs List

The first List

ys List

The second List

Source:
Returns:

The difference of xs and ys

Type
List
Example
const lst1 = list(1,2,3,4,5);
const lst2 = list(6,7,8,9,10);
const lst3 = listAppend(lst2, lst2);
deleteFirsts(lst3, lst1);                            // => [6:7:8:9:10:[]]
deleteFirsts(listAppend(lst1, lst2), lst1) === lst2; // => true

(static) deleteFirstsBy(eq, xs, ys) → {List}

Non-associative list difference: remove the first occurrence of each value of a List in turn from another List using a provided function to check for equality.
Haskell> deleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]

Parameters:
Name Type Description
eq function

A function to test for equality (must return boolean)

xs List

The first List

ys List

The second List

Source:
Returns:

The difference of xs and ys

Type
List
Example
const lst1 = list(1,2,3,4,5);
const lst2 = list(6,7,8,9,10);
const lst3 = listAppend(lst1, lst2);
const eq = (x, y) => even(x * y);
deleteFirstsBy(eq, lst3, lst1);      // => [5:7:8:9:10:[]]

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

Remove the first occurrence of a value from a List. Use deleteLBy to supply your own equality function.
Haskell> delete :: (Eq a) => a -> [a] -> [a]

Parameters:
Name Type Description
x *

The value to delete

xs List

A List

Source:
Returns:

The List with the first x deleted

Type
List
Example
const lst = list(1,2,2,3,2,4,2,2,5,2,6,7,7,8,9,10,10);
deleteL(2, lst); // => [1:2:3:2:4:2:2:5:2:6:7:7:8:9:10:10:[]]

(static) deleteLBy(eq, n, as) → {List}

Remove the first occurrence of a value from a List using a provided function to check for equality.
Haskell> deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]

Parameters:
Name Type Description
eq function

A function to test for equality (must return boolean)

n *

The value to delete

as List

A List

Source:
Returns:

The List with the first a deleted

Type
List
Example
const lst = list(1,2,2,3,2,4,2,2,5,2,6,7,7,8,9,10,10);
const eq = (x, y) => odd(x + y);
deleteLBy(eq, 2, lst); // => [2:2:3:2:4:2:2:5:2:6:7:7:8:9:10:10:[]]

(static) nub(xs) → {List}

Remove duplicate values from a List by dropping all occurrences after the first. Use nubBy to supply your own equality function.
Haskell> nub :: Eq a => [a] -> [a]

Parameters:
Name Type Description
xs List

A List

Source:
Returns:

The essence of xs

Type
List
Example
const lst = list(1,2,2,3,2,4,2,2,5,2,6,7,7,8,9,10,10);
nub(lst); // => [1:2:3:4:5:6:7:8:9:10:[]]

(static) nubBy(eq, as) → {List}

Remove duplicate values from a List by dropping all occurrences after the first. This function generalizes nub by allowing you to supply your own equality test.
Haskell> nubBy :: (a -> a -> Bool) -> [a] -> [a]

Parameters:
Name Type Description
eq function

A function to test for equality (must return boolean)

as List

A List

Source:
Returns:

The essence of as

Type
List
Example
const lst = list(1,2,2,3,2,4,2,2,5,2,6,7,7,8,9,10,10);
const eq = (x, y) => odd(x + y);
nubBy(eq, lst); // => [1:3:5:7:7:9:[]]