Methods
(static) intercalate(xs, xss) → {List}
Insert a List
in between the lists in a List
of lists. This operation is equivalent to
(concat (intersperse xs xss)).
Haskell> intercalate :: [a] -> [[a]] -> [a]
Parameters:
Name | Type | Description |
---|---|---|
xs |
List | The |
xss |
List | A |
- Source:
Returns:
The intercalated List
- Type
- List
Example
const lst1 = list(1,1,1,1,1);
const lst2 = list(2,2,2,2,2);
const lst3 = list(3,3,3,3,3);
const lst4 = list(4,4,4,4,4);
const lst5 = list(5,5,5,5,5);
const xs = list(0,0,0);
const xss = list(lst1, lst2, lst3, lst4, lst5);
// [[1:1:1:1:1:[]]:[2:2:2:2:2:[]]:[3:3:3:3:3:[]]:[4:4:4:4:4:[]]:[5:5:5:5:5:[]]:[]]
intercalate(xs, xss);
// => [1:1:1:1:1:0:0:0:2:2:2:2:2:0:0:0:3:3:3:3:3:0:0:0:4:4:4:4:4:0:0:0:5:5:5:5:5:[]]
(static) intersperse(sep, as) → {List}
Take a separator and a List
and intersperse the separator between the elements of the list.
Haskell> reverse :: [a] -> [a]
Parameters:
Name | Type | Description |
---|---|---|
sep |
* | The seperator value |
as |
List | The |
- Source:
Returns:
A new List
in which the elements of as
are interspersed with sep
- Type
- List
Example
const lst = list(1,2,3,4,5);
intersperse(0, lst); // => [1:0:2:0:3:0:4:0:5:[]]
const str = fromStringToList(`abcdefghijklmnopqrstuvwxyz`);
intersperse(`|`, str); // => [a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z]
(static) map(f, as) → {List}
Map a function over a List
and put the results into a new list. Note that a list of functions
can also be mapped over a list of values using the Applicative type class. If the functions take
multiple arguments, then the elements of the list are each applied in turn to these functions,
resulting in a new list of partially applied functions. If this list of functions is applied
again to a list of values, these new values will be applied. This process may be repeated until
the functions are all fully applied, and a list of raw values is returned. Note that only curried
functions will work in this way.
Haskell> map :: (a -> b) -> [a] -> [b]
Parameters:
Name | Type | Description |
---|---|---|
f |
function | The function to map |
as |
List | The |
- Source:
Returns:
A List
of results
- Type
- List
Example
const lst = list(1,2,3,4,5);
const f = x => x * 3;
map(f, lst)); // => [3:6:9:12:15:[]]
const lst2 = list(1,2,3);
const g = (x, y) => {
const g_ = (x, y) => x * y;
return partial(g_, x, y);
}
const lstg = list(g, g, g);
const apList = (lstg, lst2);
ap(apList, lst2); // => [1:2:3:2:4:6:3:6:9:1:2:3:2:4:6:3:6:9:1:2:3:2:4:6:3:6:9:[]]
const abc = fromStringToList(`abc`);
const abcs = list(abc);
const takeList = list(take, take, take);
const apTake = ap(takeList, lst2);
ap(apTake, abcs); // => [[a]:[ab]:[abc]:[a]:[ab]:[abc]:[a]:[ab]:[abc]:[]]
(static) reverse(xs) → {List}
Reverse the elements of a List
and return them in a new list.
Haskell> reverse :: [a] -> [a]
Parameters:
Name | Type | Description |
---|---|---|
xs |
List | A |
- Source:
Returns:
The reversed List
- Type
- List
Example
const lst = list(1,2,3,4,5);
reverse(lst); // => [5:4:3:2:1:[]]
(static) transpose(lss) → {List}
Transpose the "rows" and "columns" of a List
of lists. If some of the rows are shorter than the
following rows, their elements are skipped.
Haskell> transpose :: [[a]] -> [[a]]
Parameters:
Name | Type | Description |
---|---|---|
lss |
List | A |
- Source:
Returns:
A new List
of lists, with the rows and columns transposed
- Type
- List
Example
const lst1 = list(1,2,3);
const lst2 = list(4,5,6);
const xss1 = list(lst1, lst2);
const xss2 = list(list(10,11), list(20), list(), list(30,31,32));
transpose(xss1); // => [[1:4:[]]:[2:5:[]]:[3:6:[]]:[]]
transpose(xss2); // => [[10:20:30:[]]:[11:31:[]]:[32:[]]:[]]