Methods
(static) elemIndex(n, xs) → {Maybe}
Return the index of the first value of a List
equal to a query value, or Nothing
if there is
no such value.
Haskell> elemIndex :: Eq a => a -> [a] -> Maybe Int
Parameters:
Name | Type | Description |
---|---|---|
n |
* | The query value |
xs |
List | The |
- Source:
Returns:
Just n
or Nothing
- Type
- Maybe
Example
const lst = list(1,2,2,3,2,4,2,2,5,2,6,8);
elemIndex(8, lst); // => Just 11
elemIndex(10, lst); // => Nothing
(static) elemIndices(n, xs) → {List}
Return the indices of all values in a List
equal to a query value, in ascending order.
Haskell> elemIndices :: Eq a => a -> [a] -> [Int]
Parameters:
Name | Type | Description |
---|---|---|
n |
* | The query value |
xs |
List | The |
- Source:
Returns:
A List
of values equal to n
- Type
- List
Example
const lst = list(1,2,2,3,2,4,2,2,5,2,6,8);
elemIndices(2, lst); // => [1:2:4:6:7:9:[]]
elemIndices(10, lst); // => [[]]
(static) find(p, xs) → {Maybe}
Take a predicate function and a List
and return the first value in the list that satisfies the
predicate, or Nothing
if there is no such element. This function currently only works on List
objects, but should in the future work for all Foldable
types.
Haskell> find :: Foldable t => (a -> Bool) -> t a -> Maybe a
Parameters:
Name | Type | Description |
---|---|---|
p |
function | The predicate function |
xs |
List | The |
- Source:
Returns:
The value inside a Just
or Nothing
, otherwise
- Type
- Maybe
Example
const lst = list(1,2,3,4,5,6,7,8,9,10);
const pred1 = x => x % 3 === 0;
const pred2 = x => x > 10;
find(pred1, lst); // => Just 3
find(pred2, lst); // => Nothing
(static) findIndex(p, xs) → {Maybe}
Take a predicate function and a List
and return the index of the first value in the list that
satisfies the predicate, or Nothing
if there is no such element.
Haskell> findIndex :: (a -> Bool) -> [a] -> Maybe Int
Parameters:
Name | Type | Description |
---|---|---|
p |
function | The predicate function |
xs |
List | The |
- Source:
Returns:
The index inside a Just
or Nothing
, otherwise
- Type
- Maybe
Example
const lst = list(1,2,3,4,5,6,7,8,9,10);
const pred1 = x => x % 3 === 0;
const pred2 = x => x > 10;
findIndex(pred1, lst); // => Just 2
findIndex(pred2, lst); // => Nothing
(static) findIndices(p, xs) → {List}
Return the indices of all values in a List
that satisfy a given predicate function, in
ascending order.
Haskell> findIndices :: (a -> Bool) -> [a] -> [Int]
Parameters:
Name | Type | Description |
---|---|---|
p |
function | The predicate function |
xs |
List | The |
- Source:
Returns:
The List
of matching indices
- Type
- List
Example
const lst = list(1,2,3,4,5,6,7,8,9,10);
const pred = x => even(x);
findIndices(pred, lst); // => [1:3:5:7:9:[]]
(static) index(as, n) → {*}
Return the value from a List
at the specified index, starting at 0.
Haskell> (!!) :: [a] -> Int -> a
Parameters:
Name | Type | Description |
---|---|---|
as |
List | The |
n |
number | The index to return |
- Source:
Returns:
The value at the specified index
- Type
- *
Example
const lst = list(1,2,3,4,5);
index(lst, 3)); // => 4