import { iter , IterableOrArrayLike } from './iter' ; param object param fn returns export function find < T > ( object , fn ) { let index = 0 ; let it = iter ( object ) ; let value ; while ( ( value = it . next ( ) ) !== undefined ) { if ( fn ( value , index ++ ) ) { return value ; } } return undefined ; } param object param fn returns export function findIndex < T > ( object , fn ) { let index = 0 ; let it = iter ( object ) ; let value ; while ( ( value = it . next ( ) ) !== undefined ) { if ( fn ( value , index ++ ) ) { return index - 1 ; } } return - 1 ; } param object param fn returns export function min < T > ( object , fn ) { let it = iter ( object ) ; let value = it . next ( ) ; if ( value === undefined ) { return undefined ; } let result = value ; while ( ( value = it . next ( ) ) !== undefined ) { if ( fn ( value , result ) < 0 ) { result = value ; } } return result ; } param object param fn returns export function max < T > ( object , fn ) { let it = iter ( object ) ; let value = it . next ( ) ; if ( value === undefined ) { return undefined ; } let result = value ; while ( ( value = it . next ( ) ) !== undefined ) { if ( fn ( value , result ) > 0 ) { result = value ; } } return result ; } param object param fn returns export function minmax < T > ( object , fn ) { let it = iter ( object ) ; let value = it . next ( ) ; if ( value === undefined ) { return undefined ; } let vmin = value ; let vmax = value ; while ( ( value = it . next ( ) ) !== undefined ) { if ( fn ( value , vmin ) < 0 ) { vmin = value ; } else if ( fn ( value , vmax ) > 0 ) { vmax = value ; } } return [ vmin , vmax ] ; }