@klodianimeri/pipejs
Version:
Pipe functions that provide convenient and efficient ways to work with iterators.
52 lines (32 loc) • 1.42 kB
text/typescript
import { pipeSync } from "../src/sync/pipe-sync";
import { pipeAsync } from "../src/async/pipe-async";
import { toGeneratorSync, toGeneratorAsync } from "./sequence.test";
import { last } from '../src/pipes/last';
test('sync last', () => {
let pipe = pipeSync(toGeneratorSync([7, 4, 5]), last());
let iterator = pipe[Symbol.iterator]();
let item: IteratorResult<any> = iterator.next();
expect(item.value).toBe(5);
let done: IteratorResult<any> = iterator.next();
expect(done.value).toBeUndefined();
});
test('sync last no results', () => {
let pipe = pipeSync(toGeneratorSync([]), last());
let iterator = pipe[Symbol.iterator]();
let done: IteratorResult<any> = iterator.next();
expect(done.value).toBeUndefined();
});
test('async last', async () => {
let pipe = pipeAsync(toGeneratorAsync([7, 4, 5]), last());
let iterator = pipe[Symbol.asyncIterator]();
let item: IteratorResult<any> = await iterator.next();
expect(item.value).toBe(5);
let done: IteratorResult<any> = await iterator.next();
expect(done.value).toBeUndefined();
});
test('async last no results', async () => {
let pipe = pipeAsync(toGeneratorAsync([]), last());
let iterator = pipe[Symbol.asyncIterator]();
let done: IteratorResult<any> = await iterator.next();
expect(done.value).toBeUndefined();
});