UNPKG

@klodianimeri/pipejs

Version:

Pipe functions that provide convenient and efficient ways to work with iterators.

48 lines (28 loc) 1.33 kB
import { pipeSync } from "../src/sync/pipe-sync"; import { pipeAsync } from "../src/async/pipe-async"; import { toGeneratorSync, toGeneratorAsync } from "./sequence.test"; import { map } from '../src/pipes/map'; test('sync map', () => { let pipe = pipeSync(toGeneratorSync([1, 2, 3]), map(x => x * 2)); let iterator = pipe[Symbol.iterator](); let item0: IteratorResult<any> = iterator.next(); expect(item0.value).toEqual(2); let item1: IteratorResult<any> = iterator.next(); expect(item1.value).toEqual(4); let item2: IteratorResult<any> = iterator.next(); expect(item2.value).toEqual(6); let done: IteratorResult<any> = iterator.next(); expect(done.value).toBeUndefined(); }); test('async map', async () => { let pipe = pipeAsync(toGeneratorAsync([1, 2, 3]), map(x => x * 2)); let iterator = pipe[Symbol.asyncIterator](); let item0: IteratorResult<any> = await iterator.next(); expect(item0.value).toEqual(2); let item1: IteratorResult<any> = await iterator.next(); expect(item1.value).toEqual(4); let item2: IteratorResult<any> = await iterator.next(); expect(item2.value).toEqual(6); let done: IteratorResult<any> = await iterator.next(); expect(done.value).toBeUndefined(); });