Skip to content

Instantly share code, notes, and snippets.

@lmcarreiro
Last active March 19, 2018 15:05
Show Gist options
  • Save lmcarreiro/de3751b450e52d5944fe452eaabcf092 to your computer and use it in GitHub Desktop.
Save lmcarreiro/de3751b450e52d5944fe452eaabcf092 to your computer and use it in GitHub Desktop.
Method declaration column-indented
/**
* Filters an array by a predicate function. Returns the same array instance if the predicate is
* true for all elements, otherwise returns a new array instance containing the filtered subset.
*/
export function filter<T, U extends T>(array: T[], f: (x: T) => x is U ): U[];
export function filter<T >(array: T[], f: (x: T) => boolean): T[];
export function filter<T, U extends T>(array: ReadonlyArray<T> , f: (x: T) => x is U ): ReadonlyArray<U>;
export function filter<T, U extends T>(array: ReadonlyArray<T> , f: (x: T) => boolean): ReadonlyArray<T>;
export function filter<T >(array: T[], f: (x: T) => boolean): T[] {
if (array) {
const len = array.length;
let i = 0;
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment