tryFindIndex

Finds an Option of index of first element in an array that satisfies a predicate function. Returns None if no element is found.

Type

type tryFindIndex = <E>(predicate: ((e: E) => boolean)) => (a: Array<E>) => Option<number>

Example

import {tryFindIndex} from 'fnxt/array';

function isEven(num: number): boolean {
  return num % 2 === 0;
}

const array = [1, 2, 3, 4, 5];
const findEven = tryFindIndex(isEven);
findEven(array) // -> Some(1)

See Also