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