From 3a70457266024a1fa873a618fe55330951a09e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lazar=20Ljubenovi=C4=87?= Date: Sat, 6 Jun 2020 18:47:14 +0200 Subject: [PATCH] fix: improve typings for the filter operator (#20) Co-authored-by: Felix Becker --- src/filter.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/filter.ts b/src/filter.ts index 40b3228..cede035 100644 --- a/src/filter.ts +++ b/src/filter.ts @@ -1,12 +1,15 @@ -export class FilterIterator implements Iterator { - constructor(private source: Iterator, private predicate: (element: T) => boolean) {} +export class FilterIterator implements Iterator { + constructor( + private source: Iterator, + private predicate: ((element: T) => element is V) | ((element: T) => boolean) + ) {} - next(): IteratorResult { + next(): IteratorResult { let result: IteratorResult // Skip elements until predicate returns true do { result = this.source.next() } while (!result.done && !this.predicate(result.value)) - return result + return result as IteratorResult } }