Skip to content

Commit

Permalink
feat(type-definitions): Add type guard filter type definition variant (
Browse files Browse the repository at this point in the history
…#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
```
  • Loading branch information
thomas-jeepe authored and briancavalier committed Jun 26, 2017
1 parent aca89df commit 834fecf
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions type-definitions/most.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export interface Stream<A> extends Source<A> {
concat(s2: Stream<A>): Stream<A>;
startWith(a: A): Stream<A>;

filter<B extends A>(p: (val: A) => val is B): Stream<B>;
filter(p: (a: A) => boolean): Stream<A>;
skipRepeats(): Stream<A>;
skipRepeatsWith(eq: (a1: A, a2: A) => boolean): Stream<A>;
Expand Down Expand Up @@ -311,6 +312,10 @@ export function loop<A, B, S>(f: (seed: S, a: A) => SeedValue<S, B>, seed: S, s:
export function concat<A>(s1: Stream<A>, s2: Stream<A>): Stream<A>;
export function startWith<A>(a: A, s: Stream<A>): Stream<A>;

export function filter<A, B extends A>(
p: (val: A) => val is B,
s: Stream<A>
): Stream<B>;
export function filter<A>(p: (a: A) => boolean, s: Stream<A>): Stream<A>;
export function skipRepeats<A>(s: Stream<A>): Stream<A>;
export function skipRepeatsWith<A>(eq: (a1: A, a2: A) => boolean, s: Stream<A>): Stream<A>;
Expand Down

0 comments on commit 834fecf

Please # to comment.