import { ErrorString , InvalidOperationException } from "../../shared" ; param source param predicate throws returns export const first = < TSource > ( source , predicate ? ) : TSource => { if ( predicate ) { return first2 ( source , predicate ) ; } else { return first1 ( source ) ; } } ; const first1 = < T > ( source ) => { const first = source [ Symbol . iterator ] ( ) . next ( ) ; if ( first . done === true ) { throw new InvalidOperationException ( ErrorString . NoElements ) ; } return first . value ; } ; const first2 = < T > ( source , predicate ) : T => { for ( const value of source ) { if ( predicate ( value ) === true ) { return value ; } } throw new InvalidOperationException ( ErrorString . NoMatch ) ; } ;