param source param predicate returns export const firstOrDefault = < TSource > ( source , predicate ? ) : TSource | null => { if ( predicate ) { return firstOrDefault2 ( source , predicate ) ; } else { return firstOrDefault1 ( source ) ; } } ; const firstOrDefault1 = < T > ( source ) : T | null => { const first = source [ Symbol . iterator ] ( ) . next ( ) ; return first . value || null ; } ; const firstOrDefault2 = < T > ( source , predicate ) : T | null => { for ( const value of source ) { if ( predicate ( value ) === true ) { return value ; } } return null ; } ;