Apply a binary function to pairs of elements from two lists, returning a list of results.
expect [1, 2, 3]->map2([10, 20, 30], I64.plus) == [11, 22, 33]
Apply a binary function to pairs of elements from two lists, returning a list of results.
expect [1, 2, 3]->map2([10, 20, 30], I64.plus) == [11, 22, 33]
Create a list of pairs by combining elements from two lists at corresponding positions.
expect [1, 2, 3]->zip(["a", "b", "c"]) == [(1, "a"), (2, "b"), (3, "c")]
find_first : List(a), (a -> Bool) -> Try(a, [NotFound])
Find the first element in a list that satisfies a given predicate, returning it wrapped in Ok if found, or Err(NotFound) if no such element exists.
expect [1, 2, 3, 4]->find_first(|x| x % 2 == 0) == Ok(2)
Find the last element in a list that satisfies a given predicate, returning it wrapped in Ok if found, or Err(NotFound) if no such element exists.
expect [1, 2, 3, 4]->find_last(|x| x % 2 == 0) == Ok(4)
find_first_index : List(a), (a -> Bool) -> Try(U64, [NotFound])
Find the index of the first element in a list that satisfies a given predicate, returning it wrapped in Ok if found, or Err(NotFound) if no such element exists.
expect [1, 2, 3, 4]->find_first_index(|x| x > 1) == Ok(1)
find_last_indxex : List(a), (a -> Bool) -> Try(U64, [NotFound])
Find the index of the last element in a list that satisfies a given predicate, returning it wrapped in Ok if found, or Err(NotFound) if no such element exists.
expect [1, 2, 3, 4]->find_last_index(|x| x < 4) == Ok(2)
find_last_index : a, (b -> Bool) -> [Ok(c), Err([NotFound])] where { a.len : a -> b, a.rev : a -> List(b), c.minus : a, Dec -> a }
Split a list into two parts at a specified index, returning the part before the index and the part from the index onward.
expect [0, 1, 2, 3, 4]->split_at(2) == { before: [0, 1], others: [2, 3, 4] }
Split a list into sublists using a specified delimiter element.
expect [1, 2, 1, 2, 3]->split_on(1) == [[2], [2, 3]]
Split a list into sublists using a specified delimiter list.
expect [1, 2, 3, 4, 5]->split_on_list([2, 3]) == [[1], [4, 5]]
Split a list into sublists using a predicate function to identify delimiters.
expect [0, 1, 2, 3, 4]->split_if(|x| x % 2 == 0) == [[1], [3]]
split_first : List(a), a -> Try({ after : List(a), before : List(a) }, [NotFound]) where { a.is_eq : a, a -> Bool }
Split a list into two parts at the first occurrence of a specified delimiter element, returning the part before the delimiter and the part after it. If the delimiter is not found, return Err(NotFound).
expect [0, 1, 2, 1, 2]->split_first(2) == Ok({ before: [0, 1], after: [1, 2] })
Split a list into two parts at the first occurrence of an element that satisfies a given predicate, returning the part before the element and the part after it. If no such element is found, return Err(NotFound).
expect [0, 1, 2, 3, 4]->split_first_if(|x| x >= 2) == Ok({ before: [0, 1], after: [3, 4] })
split_last : List(a), a -> Try({ after : List(a), before : List(a) }, [NotFound]) where { a.is_eq : a, a -> Bool }
Split a list into two parts at the last occurrence of a specified delimiter element, returning the part before the delimiter and the part after it. If the delimiter is not found, return Err(NotFound).
expect [0, 1, 2, 1, 2]->split_last(1) == Ok({ before: [0, 1, 2], after: [2] })
Split a list into two parts at the last occurrence of an element that satisfies a given predicate, returning the part before the element and the part after it. If no such element is found, return Err(NotFound).
expect [0, 1, 2, 3, 4]->split_last_if(|x| x >= 2) == Ok({ before: [0, 1, 2, 3], after: [] })
Split a list into sublists at specified indices.
expect [0, 1, 2, 3, 4, 5]->split_at_indices([1, 3]) == [[0], [1, 2], [3, 4, 5]]
split_with_delims : List(a), (a -> Bool) -> List(List(a))
Split a list into sublists and include the delimiters in as single element sublists.
expect [0, 1, 0, 0]->split_with_delims(|x| x == 1) == [[0], [1], [0, 0]]
split_with_delims_head : List(a), (a -> Bool) -> List(List(a))
Split a list into sublists and include the delimiters at the head of each sublist.
expect [0, 1, 0, 0]->split_with_delims_head(|x| x == 1) == [[0], [1, 0, 0]]
split_with_delims_tail : List(a), (a -> Bool) -> List(List(a))
Split a list into sublists and include the delimiters at the tail of each sublist.
expect [0, 1, 0, 0]->split_with_delims_tail(|x| x == 1) == [[0, 1], [0, 0]]