From 834fecfbb669ebaa1aec400a97dcf377cb42d4b9 Mon Sep 17 00:00:00 2001 From: thomas-jeepe Date: Mon, 26 Jun 2017 16:50:56 -0400 Subject: [PATCH] feat(type-definitions): Add type guard filter type definition variant (#460) If someone is using a typeguard, this changes the type of the stream and makes it easier to use. Example: ```js filter(isString, from([1, 2, 'hello'])) .map(v => {}) // v at this point is inferred to be a string rather than string | number ``` --- type-definitions/most.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/type-definitions/most.d.ts b/type-definitions/most.d.ts index 4134956f..925cf9be 100644 --- a/type-definitions/most.d.ts +++ b/type-definitions/most.d.ts @@ -137,6 +137,7 @@ export interface Stream extends Source { concat(s2: Stream): Stream; startWith(a: A): Stream; + filter(p: (val: A) => val is B): Stream; filter(p: (a: A) => boolean): Stream; skipRepeats(): Stream; skipRepeatsWith(eq: (a1: A, a2: A) => boolean): Stream; @@ -311,6 +312,10 @@ export function loop(f: (seed: S, a: A) => SeedValue, seed: S, s: export function concat(s1: Stream, s2: Stream): Stream; export function startWith(a: A, s: Stream): Stream; +export function filter( + p: (val: A) => val is B, + s: Stream +): Stream; export function filter(p: (a: A) => boolean, s: Stream): Stream; export function skipRepeats(s: Stream): Stream; export function skipRepeatsWith(eq: (a1: A, a2: A) => boolean, s: Stream): Stream;