import { ErrorString , InvalidOperationException } from "../../shared" ; param source param predicate throws returns export const last = < TSource > ( source , predicate ? ) : TSource => { if ( predicate ) { return last2 ( source , predicate ) ; } else { return last1 ( source ) ; } } ; const last1 = < TSource > ( source ) : TSource => { let lastItem ; for ( const value of source ) { lastItem = value ; } if ( ! lastItem ) { throw new InvalidOperationException ( ErrorString . NoElements ) ; } return lastItem ; } ; const last2 = < TSource > ( source , predicate ) : TSource => { let lastItem ; for ( const value of source ) { if ( predicate ( value ) === true ) { lastItem = value ; } } if ( ! lastItem ) { throw new InvalidOperationException ( ErrorString . NoMatch ) ; } return lastItem ; } ;