Skip to content

Instantly share code, notes, and snippets.

@lmcarreiro
Last active March 19, 2018 15:06
Show Gist options
  • Select an option

  • Save lmcarreiro/d1787a5f789e58f9fe28de6aac1ecbb2 to your computer and use it in GitHub Desktop.

Select an option

Save lmcarreiro/d1787a5f789e58f9fe28de6aac1ecbb2 to your computer and use it in GitHub Desktop.
Method declaration not 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