···11+---
22+'wonka': minor
33+---
44+55+Add `addOne` argument to `takeWhile`, allowing an additional value to be issued.
+18
src/__tests__/operators.test.ts
···772772 operators.takeWhile((x: any) => x < 2)(source)(fn);
773773 next(1);
774774 next(2);
775775+ next(3);
775776776777 expect(fn.mock.calls).toEqual([[start(expect.any(Function))], [push(1)], [SignalKind.End]]);
778778+ });
779779+780780+ it('emits values while a predicate passes for all values plus an additional one', () => {
781781+ const { source, next } = sources.makeSubject<number>();
782782+ const fn = vi.fn();
783783+784784+ operators.takeWhile((x: any) => x < 2, true)(source)(fn);
785785+ next(1);
786786+ next(2);
787787+ next(3);
788788+789789+ expect(fn.mock.calls).toEqual([
790790+ [start(expect.any(Function))],
791791+ [push(1)],
792792+ [push(2)],
793793+ [SignalKind.End],
794794+ ]);
777795 });
778796});
779797
+6-1
src/operators.ts
···12541254/** Takes values from an input Source until a predicate function returns `false`.
12551255 *
12561256 * @param predicate - A function returning a boolean per value.
12571257+ * @param addOne - Lets an additional input value pass on.
12571258 * @returns An {@link Operator}.
12581259 *
12591260 * @remarks
12601261 * `takeWhile` will issue all values as normal from the input {@link Source} until the `predicate`
12611262 * function returns `false`. When the `predicate` function returns `false`, the current value is
12621263 * omitted and the {@link Source} is closed.
12641264+ *
12651265+ * If `addOne` is set to `true`, the value for which the `predicate` first returned `false` is
12661266+ * issued and passed on as well instead of being omitted.
12631267 *
12641268 * @example
12651269 * ```ts
···12721276 * );
12731277 * ```
12741278 */
12751275-export function takeWhile<T>(predicate: (value: T) => boolean): Operator<T, T> {
12791279+export function takeWhile<T>(predicate: (value: T) => boolean, addOne?: boolean): Operator<T, T> {
12761280 return source => sink => {
12771281 let talkback = talkbackPlaceholder;
12781282 let ended = false;
···12871291 sink(signal);
12881292 } else if (!predicate(signal[0])) {
12891293 ended = true;
12941294+ if (addOne) sink(signal);
12901295 sink(SignalKind.End);
12911296 talkback(TalkbackKind.Close);
12921297 } else {