import { curry, Predicate } from '@typed/lambda' import { Maybe, Nothing } from '@typed/maybe' import { NoInfer } from '../NoInfer' /** * Find the index of a value in an array-like starting from the end of the array-like. * @param predicate :: (a -> boolean) * @param list :: [a] * @returns :: Maybe a */ export const findLastIndex: { (predicate: Predicate>, list: ArrayLike): Maybe (predicate: Predicate): (list: ArrayLike) => Maybe } = curry(__findLastIndex) as { (predicate: Predicate>, list: ArrayLike): Maybe (predicate: Predicate): (list: ArrayLike) => Maybe } function __findLastIndex(predicate: Predicate, list: ArrayLike): Maybe { for (let i = list.length - 1; i >= 0; --i) { if (predicate(list[i])) { return Maybe.of(i) } } return Nothing }