Skip to content

Commit

Permalink
fix(takeWhileInclusive): Filter passing values.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Aug 13, 2017
1 parent e5891bc commit 08a60a9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions source/let/takeWhileInclusive-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,26 @@ describe("let/takeWhileInclusive", () => {
m.expect(destination).toBeObservable(expected);
m.expect(source).toHaveSubscriptions(subs);
}));

it("should support sources that don't emit", marbles((m) => {

const source = m.cold("-----|");
const subs = "^----!";
const expected = m.cold("-----|");

const destination = source.let(takeWhileInclusive((value) => value !== "c"));
m.expect(destination).toBeObservable(expected);
m.expect(source).toHaveSubscriptions(subs);
}));

it("should support sources that complete before a value fails the predicate", marbles((m) => {

const source = m.cold("-a-b-|");
const subs = "^----!";
const expected = m.cold("-a-b-|");

const destination = source.let(takeWhileInclusive((value) => value !== "c"));
m.expect(destination).toBeObservable(expected);
m.expect(source).toHaveSubscriptions(subs);
}));
});
3 changes: 2 additions & 1 deletion source/let/takeWhileInclusive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { Observable } from "rxjs/Observable";
import { multicast } from "rxjs/operator/multicast";
import { concat } from "rxjs/operator/concat";
import { filter } from "rxjs/operator/filter";
import { take } from "rxjs/operator/take";
import { takeWhile } from "rxjs/operator/takeWhile";
import { ReplaySubject } from "rxjs/ReplaySubject";
Expand All @@ -19,7 +20,7 @@ export function takeWhileInclusive<T>(predicate: (value: T) => boolean): (source
() => new ReplaySubject<T>(1),
(sharedSource: Observable<T>) => concat.call(
takeWhile.call(sharedSource, predicate),
take.call(sharedSource, 1)
filter.call(take.call(sharedSource, 1), (value: T) => !predicate(value))
)
);
}

0 comments on commit 08a60a9

Please sign in to comment.