Skip to content

Commit be69380

Browse files
committed
feat(takeUntil): add takeUntil function
1 parent 5ab9a17 commit be69380

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,23 @@ export function takeWhileFn<T>(
214214

215215
export const asyncTakeWhileFn = takeWhileFn;
216216

217+
export function takeUntil<T>(
218+
iterable: AsyncIterableLike<T>,
219+
predicate: (element: T, index: number) => boolean
220+
): AsyncIterable<T> {
221+
return takeWhile(iterable, (element, index) => !predicate(element, index));
222+
}
223+
224+
export const asyncTakeUntil = takeUntil;
225+
226+
export function takeUntilFn<T>(
227+
predicate: (element: T, index: number) => boolean
228+
): (iterable: AsyncIterableLike<T>) => AsyncIterable<T> {
229+
return iterable => takeUntil(iterable, predicate);
230+
}
231+
232+
export const asyncTakeUntilFn = takeUntilFn;
233+
217234
export async function* dropWhile<T>(
218235
iterable: AsyncIterableLike<T>,
219236
predicate: (element: T, index: number) => boolean

0 commit comments

Comments
 (0)