Runes
The Runes module provides enhanced Map and Array implementations that return Option types instead of undefined or -1 for operations that might not find a value.
$map
Creates a RunicMap instance with Option-returning methods.
import { $map } from 'funkcia/runes';
const map = $map([
['key1', 'value1'],
['key2', 'value2'],
]);
// Returns Option<string> instead of string | undefined
const value = map.get('key1');
// Some('value1')
const missing = map.get('key3');
// None$array
Creates a RunicArray instance with Option-returning methods.
RunicArray
An Array subclass with Option-returning methods for safer array operations.
at
Returns Some with the item at the specified index if it exists, otherwise None.
find
Returns Some with the first element matching the predicate, otherwise None.
findIndex
Returns Some with the index of the first element matching the predicate, otherwise None.
indexOf
Returns Some with the index of the first occurrence of a value, otherwise None.
lastIndexOf
Returns Some with the index of the last occurrence of a value, otherwise None.
pop
Removes and returns Some with the last element if it exists, otherwise None.
shift
Removes and returns Some with the first element if it exists, otherwise None.
Last updated
Was this helpful?