import { Index , List } from '../types' ; import { Maybe , Nothing } from '@typed/maybe' ; import { curry2 } from '@typed/functions' ; import { length } from '../length' ; name export const findLastIndex = curry2 ( __findLastIndex ) ; export type FindLastIndex = { < A > ( predicate , list ) : Maybe < Index > ; < A > ( predicate ) : ( list : List < A > ) => Maybe < Index > ; } ; function __findLastIndex < A > ( predicate , list ) { const itemCount = length ( list ) ; for ( let i = itemCount - 1 ; i >= 0 ; -- i ) if ( predicate ( list [ i ] ) ) return Maybe . of ( i ) ; return Nothing ; }