import { Index , List } from '../types' ; import { curry2 } from '@typed/functions' ; import { length } from '../length' ; name export const includes = curry2 ( __includes ) ; export type Includes = { < A > ( search , list ) : boolean ; < A > ( search ) : ( list : List < A > ) => boolean ; } ; function __includes < A > ( search , list ) { const indexes = __indexesOf ( search [ 0 ] , list ) ; return indexes . some ( __includesFromIndex ( search , list ) ) ; } function __includesFromIndex < A > ( search , list ) { const searchCount = length ( search ) ; return function ( index ) : boolean { for ( let i = 1 ; i < searchCount ; ++ i ) if ( search [ i ] !== list [ index + i ] ) return false ; return true ; } ; } function __indexesOf < A > ( value , list ) { const itemCount = length ( list ) ; const indexes = [ ] ; for ( let i = 0 ; i < itemCount ; ++ i ) if ( list [ i ] === value ) indexes . push ( i ) ; return indexes ; }