List
Utilities for working with lists.
Edit on GitHubAdded in 0.2.0
| version | changes |
|---|---|
0.1.0 | Originally named `lists` |
0.2.0 | Renamed to `list` |
from "list" include List
Functions and constants included in the List module.
Added in 0.3.0
No other changes yet.
init : (length: Number, fn: (Number => a)) => List<a>
Creates a new list of the specified length where each element is initialized with the result of an initializer function. The initializer is called with the index of each list element.
Parameters:
| param | type | description |
|---|---|---|
length | Number | The length of the new list |
fn | Number => a | The initializer function to call with each index, where the value returned will be used to initialize the element |
length: The length of the new listfn: The initializer function to call with each index, where the value returned will be used to initialize the elementReturns:
| type | description |
|---|---|
List<a> | The new list |
List<a>: The new listExamples:
List.init(5, n => n + 3) // [3, 4, 5, 6, 7]
Added in 0.1.0
| version | changes |
|---|---|
0.2.0 | Made the function tail-recursive |
length : (list: List<a>) => Number
Computes the length of the input list.
Parameters:
| param | type | description |
|---|---|---|
list | List<a> | The list to inspect |
list: The list to inspectReturns:
| type | description |
|---|---|
Number | The number of elements in the list |
Number: The number of elements in the listAdded in 0.6.0
No other changes yet.
isEmpty : (list: List<a>) => Bool
Determines if the list contains no elements.
Parameters:
| param | type | description |
|---|---|---|
list | List<a> | The list to inspect |
list: The list to inspectReturns:
| type | description |
|---|---|
Bool | true if the list is empty and false otherwise |
Bool: true if the list is empty and false otherwiseAdded in 0.1.0
No other changes yet.
reverse : (list: List<a>) => List<a>
Creates a new list with all elements in reverse order.
Parameters:
| param | type | description |
|---|---|---|
list | List<a> | The list to reverse |
list: The list to reverseReturns:
| type | description |
|---|---|
List<a> | The new list |
List<a>: The new listAdded in 0.1.0
No other changes yet.
append : (list1: List<a>, list2: List<a>) => List<a>
Creates a new list with the elements of the first list followed by the elements of the second list.
Parameters:
| param | type | description |
|---|---|---|
list1 | List<a> | The list containing elements to appear first |
list2 | List<a> | The list containing elements to appear second |
list1: The list containing elements to appear firstlist2: The list containing elements to appear secondReturns:
| type | description |
|---|---|
List<a> | The new list containing elements from list1 followed by elements from list2 |
List<a>: The new list containing elements from list1 followed by elements from list2Added in 0.1.0
No other changes yet.
contains : (search: a, list: List<a>) => Bool
Checks if the value is an element of the input list.
Uses the generic == structural equality operator.
Parameters:
| param | type | description |
|---|---|---|
search | a | The value to compare |
list | List<a> | The list to inspect |
search: The value to comparelist: The list to inspectReturns:
| type | description |
|---|---|
Bool | true if the value exists in the list or false otherwise |
Bool: true if the value exists in the list or false otherwiseAdded in 0.2.0
| version | changes |
|---|---|
0.1.0 | Originally named `foldLeft` |
0.2.0 | Renamed to `reduce` |
reduce : (fn: ((a, b) => a), initial: a, list: List<b>) => a
Combines all elements of a list using a reducer function, starting from the “head”, or left side, of the list.
In List.reduce(fn, initial, list), fn is called with
an accumulator and each element of the list, and returns
a new accumulator. The final value is the last accumulator
returned. The accumulator starts with value initial.
Parameters:
| param | type | description |
|---|---|---|
fn | (a, b) => a | The reducer function to call on each element, where the value returned will be the next accumulator value |
initial | a | The initial value to use for the accumulator on the first iteration |
list | List<b> | The list to iterate |
fn: The reducer function to call on each element, where the value returned will be the next accumulator valueinitial: The initial value to use for the accumulator on the first iterationlist: The list to iterateReturns:
| type | description |
|---|---|
a | The final accumulator returned from fn |
a: The final accumulator returned from fnExamples:
List.reduce((a, b) => a + b, 0, [1, 2, 3]) // 6
Added in 0.2.0
| version | changes |
|---|---|
0.1.0 | Originally named `foldRight` |
0.2.0 | Renamed to `reduceRight` |
reduceRight : (fn: ((a, b) => b), initial: b, list: List<a>) => b
Combines all elements of a list using a reducer function, starting from the “end”, or right side, of the list.
In List.reduceRight(fn, initial, list), fn is called with
each element of the list and an accumulator, and returns
a new accumulator. The final value is the last accumulator
returned. The accumulator starts with value initial.
Parameters:
| param | type | description |
|---|---|---|
fn | (a, b) => b | The reducer function to call on each element, where the value returned will be the next accumulator value |
initial | b | The initial value to use for the accumulator on the first iteration |
list | List<a> | The list to iterate |
fn: The reducer function to call on each element, where the value returned will be the next accumulator valueinitial: The initial value to use for the accumulator on the first iterationlist: The list to iterateReturns:
| type | description |
|---|---|
b | The final accumulator returned from fn |
b: The final accumulator returned from fnExamples:
List.reduceRight((a, b) => b ++ a, "", ["baz", "bar", "foo"]) // "foobarbaz"
Added in 0.1.0
No other changes yet.
map : (fn: (a => b), list: List<a>) => List<b>
Produces a new list initialized with the results of a mapper function called on each element of the input list.
Parameters:
| param | type | description |
|---|---|---|
fn | a => b | The mapper function to call on each element, where the value returned will be used to initialize the element in the new list |
list | List<a> | The list to iterate |
fn: The mapper function to call on each element, where the value returned will be used to initialize the element in the new listlist: The list to iterateReturns:
| type | description |
|---|---|
List<b> | The new list with mapped values |
List<b>: The new list with mapped valuesAdded in 0.1.0
No other changes yet.
mapi : (fn: ((a, Number) => b), list: List<a>) => List<b>
Produces a new list initialized with the results of a mapper function called on each element of the input list and its index.
Parameters:
| param | type | description |
|---|---|---|
fn | (a, Number) => b | The mapper function to call on each element, where the value returned will be used to initialize the element in the new list |
list | List<a> | The list to iterate |
fn: The mapper function to call on each element, where the value returned will be used to initialize the element in the new listlist: The list to iterateReturns:
| type | description |
|---|---|
List<b> | The new list with mapped values |
List<b>: The new list with mapped valuesAdded in 0.2.0
No other changes yet.
flatMap : (fn: (a => List<b>), list: List<a>) => List<b>
Produces a new list by calling a function on each element of the input list. Each iteration produces an intermediate list, which are all appended to produce a “flattened” list of all results.
Parameters:
| param | type | description |
|---|---|---|
fn | a => List<b> | The function to be called on each element, where the value returned will be a list that gets appended to the new list |
list | List<a> | The list to iterate |
fn: The function to be called on each element, where the value returned will be a list that gets appended to the new listlist: The list to iterateReturns:
| type | description |
|---|---|
List<b> | The new list |
List<b>: The new listAdded in 0.1.0
No other changes yet.
every : (fn: (a => Bool), list: List<a>) => Bool
Checks that the given condition is satisfied for all elements in the input list.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Bool | The function to call on each element, where the returned value indicates if the element satisfies the condition |
list | List<a> | The list to check |
fn: The function to call on each element, where the returned value indicates if the element satisfies the conditionlist: The list to checkReturns:
| type | description |
|---|---|
Bool | true if all elements satify the condition or false otherwise |
Bool: true if all elements satify the condition or false otherwiseAdded in 0.1.0
No other changes yet.
some : (fn: (a => Bool), list: List<a>) => Bool
Checks that the given condition is satisfied at least once by an element in the input list.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Bool | The function to call on each element, where the returned value indicates if the element satisfies the condition |
list | List<a> | The list to iterate |
fn: The function to call on each element, where the returned value indicates if the element satisfies the conditionlist: The list to iterateReturns:
| type | description |
|---|---|
Bool | true if one or more elements satify the condition or false otherwise |
Bool: true if one or more elements satify the condition or false otherwiseAdded in 0.1.0
No other changes yet.
forEach : (fn: (a => Void), list: List<a>) => Void
Iterates a list, calling an iterator function on each element.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Void | The iterator function to call with each element |
list | List<a> | The list to iterate |
fn: The iterator function to call with each elementlist: The list to iterateAdded in 0.1.0
No other changes yet.
forEachi : (fn: ((a, Number) => Void), list: List<a>) => Void
Iterates a list, calling an iterator function on each element. Also passes the index as the second argument to the function.
Parameters:
| param | type | description |
|---|---|---|
fn | (a, Number) => Void | The iterator function to call with each element |
list | List<a> | The list to iterate |
fn: The iterator function to call with each elementlist: The list to iterateAdded in 0.1.0
No other changes yet.
filter : (fn: (a => Bool), list: List<a>) => List<a>
Produces a new list by calling a function on each element of the input list and only including it in the result list if the element satisfies the condition.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Bool | The function to call on each element, where the returned value indicates if the element satisfies the condition |
list | List<a> | The list to iterate |
fn: The function to call on each element, where the returned value indicates if the element satisfies the conditionlist: The list to iterateReturns:
| type | description |
|---|---|
List<a> | The new list containing elements where fn returned true |
List<a>: The new list containing elements where fn returned trueAdded in 0.3.0
No other changes yet.
filteri : (fn: ((a, Number) => Bool), list: List<a>) => List<a>
Produces a new list by calling a function on each element of the input list and only including it in the result list if the element satisfies the condition. Also passes the index to the function.
Parameters:
| param | type | description |
|---|---|---|
fn | (a, Number) => Bool | The function to call on each element, where the returned value indicates if the element satisfies the condition |
list | List<a> | The list to iterate |
fn: The function to call on each element, where the returned value indicates if the element satisfies the conditionlist: The list to iterateReturns:
| type | description |
|---|---|
List<a> | The new list containing elements where fn returned true |
List<a>: The new list containing elements where fn returned trueAdded in 0.1.0
No other changes yet.
reject : (fn: (a => Bool), list: List<a>) => List<a>
Produces a new list by calling a function on each element of the input list and excluding it from the result list if the element satisfies the condition.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Bool | The function to call on each element, where the returned value indicates if the element satisfies the condition |
list | List<a> | The list to iterate |
fn: The function to call on each element, where the returned value indicates if the element satisfies the conditionlist: The list to iterateReturns:
| type | description |
|---|---|
List<a> | The new list containing elements where fn returned false |
List<a>: The new list containing elements where fn returned falseAdded in 0.2.0
| version | changes |
|---|---|
0.1.0 | Originally named `hd` |
0.2.0 | Renamed to `head` |
0.3.0 | Return type converted to `Option` type |
head : (list: List<a>) => Option<a>
Provides Some(element) containing the first element, or “head”, of
the input list or None if the list is empty.
Parameters:
| param | type | description |
|---|---|---|
list | List<a> | The list to access |
list: The list to accessReturns:
| type | description |
|---|---|
Option<a> | Some(firstElement) if the list has elements or None otherwise |
Option<a>: Some(firstElement) if the list has elements or None otherwiseAdded in 0.2.0
| version | changes |
|---|---|
0.1.0 | Originally named `tl` |
0.2.0 | Renamed to `tail` |
0.3.0 | Return type converted to `Option` type |
tail : (list: List<a>) => Option<List<a>>
Provides Some(tail) containing all list items except the first element, or “tail”, of
the input list or None if the list is empty.
Parameters:
| param | type | description |
|---|---|---|
list | List<a> | The list to access |
list: The list to accessReturns:
| type | description |
|---|---|
Option<List<a>> | Some(tail) if the list has elements or None otherwise |
Option<List<a>>: Some(tail) if the list has elements or None otherwiseAdded in 0.1.0
| version | changes |
|---|---|
0.1.0 | Originally failed for index out-of-bounds or list empty |
0.3.0 | Return type converted to `Option` type |
nth : (index: Number, list: List<a>) => Option<a>
Provides Some(element) containing the element in the list at the specified index
or None if the index is out-of-bounds or the list is empty.
Parameters:
| param | type | description |
|---|---|---|
index | Number | The index to access |
list | List<a> | The list to access |
index: The index to accesslist: The list to accessReturns:
| type | description |
|---|---|
Option<a> | Some(element) if the list contains an element at the index or None otherwise |
Option<a>: Some(element) if the list contains an element at the index or None otherwiseAdded in 0.1.0
No other changes yet.
flatten : (list: List<List<a>>) => List<a>
Flattens nested lists.
Parameters:
| param | type | description |
|---|---|---|
list | List<List<a>> | The list to flatten |
list: The list to flattenReturns:
| type | description |
|---|---|
List<a> | A new list containing all nested list elements combined |
List<a>: A new list containing all nested list elements combinedExamples:
List.flatten([[1, 2], [3, 4]]) // [1, 2, 3, 4]
Added in 0.1.0
| version | changes |
|---|---|
0.6.0 | Swapped order of `index` and `value` parameters |
insert : (index: Number, value: a, list: List<a>) => List<a>
Inserts a new value into a list at the specified index.
Parameters:
| param | type | description |
|---|---|---|
index | Number | The index to update |
value | a | The value to insert |
list | List<a> | The list to update |
index: The index to updatevalue: The value to insertlist: The list to updateReturns:
| type | description |
|---|---|
List<a> | The new list |
List<a>: The new listThrows:
Failure(String)
- When
indexis negative - When
indexis more than 0 and greater than the list size
Added in 0.1.0
| version | changes |
|---|---|
0.2.0 | Made the function tail-recursive |
count : (fn: (a => Bool), list: List<a>) => Number
Counts the number of elements in a list that satisfy the given condition.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Bool | The function to call on each element, where the returned value indicates if the element satisfies the condition |
list | List<a> | The list to iterate |
fn: The function to call on each element, where the returned value indicates if the element satisfies the conditionlist: The list to iterateReturns:
| type | description |
|---|---|
Number | The total number of elements that satisfy the condition |
Number: The total number of elements that satisfy the conditionAdded in 0.1.0
No other changes yet.
part : (count: Number, list: List<a>) => (List<a>, List<a>)
Split a list into two, with the first list containing the required number of elements.
Parameters:
| param | type | description |
|---|---|---|
count | Number | The number of elements required |
list | List<a> | The list to split |
count: The number of elements requiredlist: The list to splitReturns:
| type | description |
|---|---|
(List<a>, List<a>) | Two lists where the first contains exactly the required amount of elements and the second contains any remaining elements |
(List<a>, List<a>): Two lists where the first contains exactly the required amount of elements and the second contains any remaining elementsThrows:
Failure(String)
- When
countis negative - When the list doesn’t contain at least the required amount of elements
Added in 0.1.0
| version | changes |
|---|---|
0.6.0 | No longer throws if `count` outside list length bounds |
rotate : (n: Number, list: List<a>) => List<a>
Rotates list elements by the specified amount to the left, such that nth
element is the first in the new list.
If value is negative, list elements will be rotated by the specified amount to the right. See examples.
Parameters:
| param | type | description |
|---|---|---|
n | Number | The number of elements to rotate by |
list | List<a> | The list to be rotated |
n: The number of elements to rotate bylist: The list to be rotatedExamples:
List.rotate(2, [1, 2, 3, 4, 5]) // [3, 4, 5, 1, 2]
List.rotate(-1, [1, 2, 3, 4, 5]) // [5, 1, 2, 3, 4]
List.rotate(-7, [1, 2, 3, 4, 5]) // [4, 5, 1, 2, 3]
Added in 0.2.0
| version | changes |
|---|---|
0.1.0 | Originally named `uniq` |
0.2.0 | Renamed to `unique` |
unique : (list: List<a>) => List<a>
Produces a new list with any duplicates removed.
Uses the generic == structural equality operator.
Parameters:
| param | type | description |
|---|---|---|
list | List<a> | The list to filter |
list: The list to filterReturns:
| type | description |
|---|---|
List<a> | The new list with only unique values |
List<a>: The new list with only unique valuesAdded in 0.5.3
No other changes yet.
zip : (list1: List<a>, list2: List<b>) => List<(a, b)>
Produces a new list filled with tuples of elements from both given lists. The first tuple will contain the first item of each list, the second tuple will contain the second item of each list, and so on.
Calling this function with lists of different sizes will cause the returned list to have the length of the smaller list.
Parameters:
| param | type | description |
|---|---|---|
list1 | List<a> | The list to provide values for the first tuple element |
list2 | List<b> | The list to provide values for the second tuple element |
list1: The list to provide values for the first tuple elementlist2: The list to provide values for the second tuple elementReturns:
| type | description |
|---|---|
List<(a, b)> | The new list containing indexed pairs of (a, b) |
List<(a, b)>: The new list containing indexed pairs of (a, b)Examples:
List.zip([1, 2, 3], [4, 5, 6]) // [(1, 4), (2, 5), (3, 6)]
List.zip([1, 2, 3], [4, 5]) // [(1, 4), (2, 5)]
Added in 0.5.3
No other changes yet.
zipWith : (fn: ((a, b) => c), list1: List<a>, list2: List<b>) => List<c>
Produces a new list filled with elements defined by applying a function on pairs from both given lists. The first element will contain the result of applying the function to the first elements of each list, the second element will contain the result of applying the function to the second elements of each list, and so on.
Calling this function with lists of different sizes will cause the returned list to have the length of the smaller list.
Parameters:
| param | type | description |
|---|---|---|
fn | (a, b) => c | The function to apply to pairs of elements |
list1 | List<a> | The list whose elements will each be passed to the function as the first argument |
list2 | List<b> | The list whose elements will each be passed to the function as the second argument |
fn: The function to apply to pairs of elementslist1: The list whose elements will each be passed to the function as the first argumentlist2: The list whose elements will each be passed to the function as the second argumentReturns:
| type | description |
|---|---|
List<c> | The new list containing elements derived from applying the function to pairs of input list elements |
List<c>: The new list containing elements derived from applying the function to pairs of input list elementsExamples:
List.zipWith((a, b) => a + b, [1, 2, 3], [4, 5, 6]) // [5, 7, 9]
List.zipWith((a, b) => a * b, [1, 2, 3], [4, 5]) // [4, 10]
Added in 0.5.3
No other changes yet.
unzip : (list: List<(a, b)>) => (List<a>, List<b>)
Produces two lists by splitting apart a list of tuples.
Parameters:
| param | type | description |
|---|---|---|
list | List<(a, b)> | The list of tuples to split |
list: The list of tuples to splitReturns:
| type | description |
|---|---|
(List<a>, List<b>) | An list containing all elements from the first tuple element, and a list containing all elements from the second tuple element |
(List<a>, List<b>): An list containing all elements from the first tuple element, and a list containing all elements from the second tuple elementAdded in 0.2.0
No other changes yet.
drop : (count: Number, list: List<a>) => List<a>
Produces a new list with the specified number of elements removed from the beginning of the input list.
Parameters:
| param | type | description |
|---|---|---|
count | Number | The amount of elements to remove |
list | List<a> | The input list |
count: The amount of elements to removelist: The input listReturns:
| type | description |
|---|---|
List<a> | The new list without the dropped elements |
List<a>: The new list without the dropped elementsThrows:
Failure(String)
- When
countis negative
Added in 0.2.0
No other changes yet.
dropWhile : (fn: (a => Bool), list: List<a>) => List<a>
Produces a new list with the elements removed from the beginning
of the input list until they no longer satisfy the given condition.
Stops when the predicate function returns false.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Bool | The function to call on each element, where the returned value indicates if the element satisfies the condition |
list | List<a> | The input list |
fn: The function to call on each element, where the returned value indicates if the element satisfies the conditionlist: The input listReturns:
| type | description |
|---|---|
List<a> | The new list without the dropped elements |
List<a>: The new list without the dropped elementsAdded in 0.2.0
No other changes yet.
take : (count: Number, list: List<a>) => List<a>
Produces a new list with–at most—the specified amount elements from the beginning of the input list.
Parameters:
| param | type | description |
|---|---|---|
count | Number | The amount of elements to keep |
list | List<a> | The input list |
count: The amount of elements to keeplist: The input listReturns:
| type | description |
|---|---|
List<a> | The new list containing the taken elements |
List<a>: The new list containing the taken elementsThrows:
Failure(String)
- When
countis negative
Added in 0.2.0
No other changes yet.
takeWhile : (fn: (a => Bool), list: List<a>) => List<a>
Produces a new list with elements from the beginning of the input list
as long as they satisfy the given condition.
Stops when the predicate function returns false.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Bool | The function to call on each element, where the returned value indicates if the element satisfies the condition |
list | List<a> | The input list |
fn: The function to call on each element, where the returned value indicates if the element satisfies the conditionlist: The input listReturns:
| type | description |
|---|---|
List<a> | The new list containing the taken elements |
List<a>: The new list containing the taken elementsAdded in 0.2.0
| version | changes |
|---|---|
0.2.0 | Originally failed if the list was empty |
0.3.0 | Return type converted to `Option` type |
find : (fn: (a => Bool), list: List<a>) => Option<a>
Finds the first element in a list that satifies the given condition.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Bool | The function to call on each element, where the returned value indicates if the element satisfies the condition |
list | List<a> | The list to search |
fn: The function to call on each element, where the returned value indicates if the element satisfies the conditionlist: The list to searchReturns:
| type | description |
|---|---|
Option<a> | Some(element) containing the first value found or None otherwise |
Option<a>: Some(element) containing the first value found or None otherwiseAdded in 0.2.0
| version | changes |
|---|---|
0.2.0 | Originally failed if the list was empty |
0.3.0 | Return type converted to `Option` type |
findIndex : (fn: (a => Bool), list: List<a>) => Option<Number>
Finds the first index in a list where the element satifies the given condition.
Parameters:
| param | type | description |
|---|---|---|
fn | a => Bool | The function to call on each element, where the returned value indicates if the element satisfies the condition |
list | List<a> | The list to search |
fn: The function to call on each element, where the returned value indicates if the element satisfies the conditionlist: The list to searchReturns:
| type | description |
|---|---|
Option<Number> | Some(index) containing the index of the first element found or None otherwise |
Option<Number>: Some(index) containing the index of the first element found or None otherwiseAdded in 0.2.0
No other changes yet.
product : (list1: List<a>, list2: List<b>) => List<(a, b)>
Combines two lists into a Cartesian product of tuples containing
all ordered pairs (a, b).
Parameters:
| param | type | description |
|---|---|---|
list1 | List<a> | The list to provide values for the first tuple element |
list2 | List<b> | The list to provide values for the second tuple element |
list1: The list to provide values for the first tuple elementlist2: The list to provide values for the second tuple elementReturns:
| type | description |
|---|---|
List<(a, b)> | The new list containing all pairs of (a, b) |
List<(a, b)>: The new list containing all pairs of (a, b)Added in 0.2.0
No other changes yet.
sub : (start: Number, length: Number, list: List<a>) => List<a>
Provides the subset of a list given zero-based start index and amount of elements to include.
Parameters:
| param | type | description |
|---|---|---|
start | Number | The index of the list where the subset will begin (inclusive) |
length | Number | The amount of elements to be included in the subset |
list | List<a> | The input list |
start: The index of the list where the subset will begin (inclusive)length: The amount of elements to be included in the subsetlist: The input listReturns:
| type | description |
|---|---|
List<a> | The subset of the list |
List<a>: The subset of the listThrows:
Failure(String)
- When
startis negative - When
lengthis negative
Added in 0.4.0
No other changes yet.
join : (separator: String, list: List<String>) => String
Combine the given list of strings into one string with the specified separator inserted between each item.
Parameters:
| param | type | description |
|---|---|---|
separator | String | The separator to insert between elements |
list | List<String> | The list to combine |
separator: The separator to insert between elementslist: The list to combineReturns:
| type | description |
|---|---|
String | The combined elements with the separator between each |
String: The combined elements with the separator between eachAdded in 0.4.5
No other changes yet.
revAppend : (list1: List<a>, list2: List<a>) => List<a>
Reverses the first list and appends the second list to the end.
Parameters:
| param | type | description |
|---|---|---|
list1 | List<a> | The list to reverse |
list2 | List<a> | The list to append |
list1: The list to reverselist2: The list to appendReturns:
| type | description |
|---|---|
List<a> | The new list |
List<a>: The new listAdded in 0.4.5
| version | changes |
|---|---|
0.6.0 | Made `compare` a default argument |
sort : (?compare: ((num1: a, num2: a) => Number), list: List<a>) => List<a>
Sorts the given list based on a given comparator function. The resulting list is sorted in increasing order.
Ordering is calculated using a comparator function which takes two list elements and must return 0 if both are equal, a positive number if the first is greater, and a negative number if the first is smaller.
Parameters:
| param | type | description |
|---|---|---|
?compare | (num1: a, num2: a) => Number | The comparator function used to indicate sort order |
list | List<a> | The list to be sorted |
?compare: The comparator function used to indicate sort orderlist: The list to be sortedReturns:
| type | description |
|---|---|
List<a> | The sorted list |
List<a>: The sorted list