repo_name
stringlengths
5
122
path
stringlengths
3
232
text
stringlengths
6
1.05M
syrflover/iterator-helper
src/methods/nub.ts
import { getLogger } from '../logger.ts'; import { nubBy } from './nubBy.ts'; const logger = await getLogger('methods/nub'); export function nub<T>(iter: AsyncIterable<T>): AsyncIterable<T> { logger.trace('nub()'); return nubBy<T>((a, b) => a === b, iter); }
syrflover/iterator-helper
src/methods/filter_test.ts
<reponame>syrflover/iterator-helper import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { iterator } from '../mod.ts'; Deno.test('filter() is even', async () => { const a = iterator([1, 2, 3, 4, 5, 6]); const actual: number[] = []; const expected = [2, 4, 6]; for await (c...
syrflover/iterator-helper
src/types/functions/mod.ts
export * from './compare.ts'; export * from './equal.ts'; export * from './fold.ts'; export * from './forEach.ts'; export * from './key.ts'; export * from './map.ts'; export * from './predicate.ts'; export * from './scan.ts';
syrflover/iterator-helper
bench/filter.ts
import { BenchmarkTimer, BenchmarkDefinition } from 'https://deno.land/std/testing/bench.ts'; import { iterator } from '../mod.ts'; async function* range_async(end: number) { let i = 0; const e = end + 1; while (i < e) { yield i; i++; } } function* range_sync(end: number) { let i =...
syrflover/iterator-helper
deno/methods/forEach.ts
import type { ForEachFn } from "../types/functions/mod.ts"; import { _curry } from "../lib/utils/mod.ts"; async function _for_each_impl_fn<T>( fn: ForEachFn<T>, iter: AsyncIterable<T>, ): Promise<void> { for await (const elem of iter) { await fn(elem); } } export interface ForEach { <T>(fn: ForEachFn<T...
syrflover/iterator-helper
src/types/functions/forEach.ts
<filename>src/types/functions/forEach.ts export type ForEachFn<T> = (elem: T) => void | Promise<void>;
syrflover/iterator-helper
src/methods/flatMap_test.ts
<reponame>syrflover/iterator-helper<gh_stars>1-10 import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { iterator } from '../mod.ts'; Deno.test(`flatMap() [\`it's Sunny in\`, '', 'California'] split(' ')`, async () => { const a = iterator([`it's Sunny in`, '', 'California']); const...
syrflover/iterator-helper
src/lib/iterable/append_test.ts
<gh_stars>1-10 import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { append } from './mod.ts'; Deno.test('append(1, [0])', async () => { const actual: number[] = []; const expected = [0, 1]; for await (const _ of append(1, [0])) { actual.push(_); } assertEqual...
syrflover/iterator-helper
deno/methods/maxByKey.ts
import type { CompareFn, KeyFn } from "../types/functions/mod.ts"; import { maxBy as compare_maxBy } from "../lib/compare/mod.ts"; import { next_async } from "../lib/iterable/mod.ts"; import { _curry, Curry2 } from "../lib/utils/mod.ts"; import { fold } from "./fold.ts"; async function _max_by_key_impl_fn<T, K>( k...
syrflover/iterator-helper
src/logger.ts
<gh_stars>1-10 // import * as log from 'https://deno.land/std/log/mod.ts'; import { Logger, LogRecord } from 'https://deno.land/std/log/logger.ts'; import { LogLevels, getLevelByName } from 'https://deno.land/std/log/levels.ts'; import { BaseHandler } from 'https://deno.land/std/log/handlers.ts'; import { blue, cyan, g...
syrflover/iterator-helper
src/methods/partition_test.ts
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { iterator } from '../mod.ts'; Deno.test('partition() even', async () => { const a = iterator([1, 2, 3, Promise.resolve(4), 5]); const actual_left: number[] = []; const expected_left = [2, 4]; const actual_right: number[...
syrflover/iterator-helper
deno/methods/collect.ts
import { fold } from "./fold.ts"; export function collect<T>(iter: AsyncIterable<T>): Promise<T[]> { return fold((acc: T[], e: T) => [...acc, e], [] as T[], iter); }
syrflover/iterator-helper
src/methods/fold_test.ts
<reponame>syrflover/iterator-helper import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { iterator } from '../mod.ts'; Deno.test('fold() sum', async () => { const a = iterator([1, 2, 3, Promise.resolve(4), 5]); const actual_elements: number[] = []; const expected_elements = [1...
syrflover/iterator-helper
deno/lib/compare/mod.ts
<gh_stars>1-10 export * from './compare.ts'; export * from './maxBy.ts'; export * from './max.ts'; export * from './minBy.ts'; export * from './min.ts';
syrflover/iterator-helper
src/methods/head.ts
<reponame>syrflover/iterator-helper<filename>src/methods/head.ts import { getLogger } from '../logger.ts'; import { next_async } from '../lib/iterable/mod.ts'; const logger = await getLogger('methods/head'); async function _head_impl_fn<T>(iter: AsyncIterable<T>): Promise<T | undefined> { logger.trace('head()');...
syrflover/iterator-helper
scripts/test.ts
<filename>scripts/test.ts /* eslint-disable */ import { $ } from '../src/lib/utils/mod.ts'; import { collect } from '../src/methods/mod.ts'; async function* getFileNamesInDirectory(dir: string): AsyncIterable<string> { const excludes = ['src/playground.ts', 'src/logger.ts', 'src/iterator.ts']; const files = D...
syrflover/iterator-helper
mod.ts
export * from './deno/mod.ts';
syrflover/iterator-helper
deno/methods/fold.ts
import type { FoldFn } from "../types/functions/mod.ts"; import { _curry, Curry2 } from "../lib/utils/mod.ts"; async function _fold_impl_fn<A, B>( fn: FoldFn<A, B>, init: B | Promise<B>, iter: AsyncIterable<A>, ): Promise<B> { let acc = await init; for await (const elem of iter) { acc = await fn(acc, e...
syrflover/iterator-helper
src/methods/takeWhile_test.ts
<filename>src/methods/takeWhile_test.ts import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { iterator } from '../mod.ts'; Deno.test('takeWhile(x < 3, [1,2,3,4,1,2,3,4]) == [1,2]', async () => { const a = iterator([1, 2, 3, 4, 1, 2, 3, 4]); const actual: number[] = []; const e...
syrflover/iterator-helper
deno/methods/enumerate.ts
<filename>deno/methods/enumerate.ts import { Pair, pair } from "../types/mod.ts"; import { next_async } from "../lib/iterable/mod.ts"; import { scan } from "./scan.ts"; async function* _enumerate_impl_fn<T>( iter: AsyncIterable<T>, ): AsyncIterable<Pair<number, T>> { const { done, value } = await next_async(iter...
syrflover/iterator-helper
src/types/mod.ts
<reponame>syrflover/iterator-helper export type { Flatten } from './flatten.ts'; export type { Nullable } from './nullable.ts'; export type { Pair } from './pair.ts'; export type { ExtractPromise, EP } from './promise.ts'; export { Ord } from './ordering.ts'; export { pair } from './pair.ts';
syrflover/iterator-helper
src/methods/findMap_test.ts
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { iterator } from '../mod.ts'; Deno.test('findMap() parseInt Succeeded', async () => { const a = iterator(['a', 'b', '1', 'c', '2', '3']); const actual = await a.findMap((e) => parseInt(e, 10)); const expected = 1; asser...
syrflover/iterator-helper
deno/methods/minBy.ts
<reponame>syrflover/iterator-helper<filename>deno/methods/minBy.ts<gh_stars>1-10 import type { CompareFn } from "../types/functions/mod.ts"; import { _curry, id } from "../lib/utils/mod.ts"; import { minByKey } from "./minByKey.ts"; export interface MinBy { <T>(fn: CompareFn<T>, iter: AsyncIterable<T>): Promise<T ...
syrflover/iterator-helper
deno/methods/last.ts
<gh_stars>1-10 import { fold } from "./fold.ts"; // [a] -> Maybe a export function last<T>(iter: AsyncIterable<T>): Promise<T | undefined> { return fold((_, e) => e, undefined as T | undefined, iter); }
syrflover/iterator-helper
src/types/guards/isIterable.ts
<filename>src/types/guards/isIterable.ts import { isFunction } from './isFunction.ts'; import { isNull } from './isNull.ts'; export function isIterable(a: any): a is Iterable<any> { return isNull(a) ? false : isFunction(a[Symbol.iterator]); }
syrflover/iterator-helper
src/methods/maxBy.ts
<filename>src/methods/maxBy.ts<gh_stars>1-10 import type { CompareFn } from '../types/functions/mod.ts'; import { getLogger } from '../logger.ts'; import { _curry, id } from '../lib/utils/mod.ts'; import { maxByKey } from './maxByKey.ts'; const logger = await getLogger('methods/maxBy'); export interface MaxBy { ...
syrflover/iterator-helper
src/methods/skip.ts
import { getLogger } from '../logger.ts'; import { next_async } from '../lib/iterable/mod.ts'; import { _curry } from '../lib/utils/mod.ts'; const logger = await getLogger('methods/skip'); async function* _skip_impl_fn<T>(count: number, iter: AsyncIterable<T>): AsyncIterable<T> { logger.trace('skip()'); let...
syrflover/iterator-helper
src/lib/compare/minBy_test.ts
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { id } from '../utils/mod.ts'; import { compare, minBy } from './mod.ts'; Deno.test('minBy(100, 1, compare) == 1', async () => { const actual = await minBy(id, compare, 100, 1); const expected = 1; assertEquals(actual, expect...
syrflover/iterator-helper
deno/methods/partition.ts
import type { PredicateFn } from "../types/functions/mod.ts"; import { Pair, pair } from "../types/mod.ts"; import { append, sequence } from "../lib/iterable/mod.ts"; import { _curry } from "../lib/utils/mod.ts"; import { fold } from "./fold.ts"; async function _partition_impl_fn<T>( fn: PredicateFn<T>, iter: A...
syrflover/iterator-helper
src/methods/skipWhile.ts
<reponame>syrflover/iterator-helper import type { PredicateFn } from '../types/functions/mod.ts'; import { getLogger } from '../logger.ts'; import { next_async, prepend } from '../lib/iterable/mod.ts'; import { _curry } from '../lib/utils/mod.ts'; const logger = await getLogger('methods/dropWhile'); async function*...
syrflover/iterator-helper
src/types/functions/map.ts
export type MapFn<T, R> = (elem: T) => R | Promise<R>;
syrflover/iterator-helper
src/types/guards/isPromise_test.ts
<reponame>syrflover/iterator-helper import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { isPromise } from './mod.ts'; Deno.test('isPromise() true', () => { const actual = isPromise(Promise.resolve()); const expected = true; assertEquals(actual, expected); }); Deno.test('isPr...
syrflover/iterator-helper
deno/iterator.ts
import type { ForEachFn, FoldFn, MapFn, PredicateFn, CompareFn, KeyFn, ScanFn, EqualFn } from './types/functions/mod.ts'; import { compare } from './lib/compare/mod.ts'; import { next_async, sequence } from './lib/iterable/mod.ts'; import { Flatten, Pair, pair, Nullable } from './types/mod.ts'; import { all, ...
syrflover/iterator-helper
src/types/guards/isNull.ts
/** * a is null | undefined | NaN */ export function isNull(a: any): a is null | undefined { return a === null || a === undefined || Number.isNaN(a); }
syrflover/iterator-helper
src/methods/scan1_test.ts
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { iterator } from '../mod.ts'; Deno.test('scan1() state + elem', async () => { const a = iterator([1, 2, 3, Promise.resolve(4), 5]); const actual_elements: number[] = []; const expected_elements = [2, 3, 4, 5]; const act...
syrflover/iterator-helper
src/types/ordering.ts
/* eslint-disable no-shadow */ export enum Ord { Less = -1, Equal = 0, Greater = 1, }
syrflover/iterator-helper
src/methods/zip_test.ts
<reponame>syrflover/iterator-helper<filename>src/methods/zip_test.ts import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import type { Pair } from '../types/mod.ts'; import { iterator } from '../mod.ts'; Deno.test('zip() [1,2,3,4].zip([5,6,7,8])', async () => { const a = iterator([1, 2, 3, 4]...
syrflover/iterator-helper
src/methods/count_test.ts
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { iterator } from '../mod.ts'; Deno.test('count() [1,2,3,4,5].length === count()', async () => { const a = [1, 2, 3, 4, 5]; const actual = await iterator([1, 2, 3, 4, 5]).count(); const expected = a.length; assertEquals(...
syrflover/iterator-helper
deno/methods/head.ts
<reponame>syrflover/iterator-helper import { next_async } from "../lib/iterable/mod.ts"; async function _head_impl_fn<T>( iter: AsyncIterable<T>, ): Promise<T | undefined> { const { done, value } = await next_async(iter); if (done) { return; } return value; } export function head<T>(iter: AsyncIterabl...
syrflover/iterator-helper
src/methods/average.ts
<filename>src/methods/average.ts import { getLogger } from '../logger.ts'; import { pair, Pair } from '../types/mod.ts'; import { fold } from './fold.ts'; export const logger = await getLogger('methods/average'); async function _average_impl_fn(iter: AsyncIterable<number>) { logger.trace('average()'); const...
syrflover/iterator-helper
src/methods/take.ts
import { getLogger } from '../logger.ts'; import { _curry } from '../lib/utils/mod.ts'; const logger = await getLogger('methods/take'); async function* _take_impl_fn<T>(limit: number, iter: AsyncIterable<T>): AsyncIterable<T> { logger.trace('take()'); let current = 1; for await (const elem of iter) { ...
syrflover/iterator-helper
deno/methods/flatten.ts
import type { Flatten } from "../types/mod.ts"; import { isAsyncIterable, isIterable } from "../types/guards/mod.ts"; async function* _flatten_impl_fn<T>( iter: AsyncIterable<T>, ): AsyncIterable<Flatten<T>> { for await (const elem of iter) { if (isIterable(elem) || isAsyncIterable(elem)) { yield* elem;...
syrflover/iterator-helper
deno/methods/scan1.ts
import type { ScanFn } from "../types/functions/mod.ts"; import { next_async } from "../lib/iterable/mod.ts"; import { _curry } from "../lib/utils/mod.ts"; import { scan } from "./scan.ts"; async function* _scan1_impl_fn<T>( fn: ScanFn<T, T>, iter: AsyncIterable<T>, ): AsyncIterable<T> { const { done, value: h...
syrflover/iterator-helper
src/methods/nubBy.ts
import type { EqualFn } from '../types/functions/mod.ts'; import { getLogger } from '../logger.ts'; import { sequence } from '../lib/iterable/mod.ts'; import { _curry } from '../lib/utils/mod.ts'; import { any } from './any.ts'; const logger = await getLogger('methods/nubBy'); async function* _nub_by_impl_fn<T>(fn...
syrflover/iterator-helper
deno/methods/nub.ts
<reponame>syrflover/iterator-helper import { nubBy } from "./nubBy.ts"; export function nub<T>(iter: AsyncIterable<T>): AsyncIterable<T> { return nubBy<T>((a, b) => a === b, iter); }
syrflover/iterator-helper
deno/methods/filterMap.ts
import type { Nullable } from "../types/mod.ts"; import type { MapFn } from "../types/functions/mod.ts"; import { isNull } from "../types/guards/mod.ts"; import { _curry } from "../lib/utils/mod.ts"; async function* _filter_map_impl_fn<T, R>( fn: MapFn<T, Nullable<R>>, iter: AsyncIterable<T>, ): AsyncIterable<R>...
syrflover/iterator-helper
src/types/guards/isString.ts
import { isNull } from './isNull.ts'; export function isString(a: any): a is string { return isNull(a) ? false : a.constructor === String; }
syrflover/iterator-helper
src/lib/iterable/prepend_test.ts
<reponame>syrflover/iterator-helper import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { prepend } from './mod.ts'; Deno.test('prepend(0, [1])', async () => { const actual: number[] = []; const expected = [0, 1]; for await (const _ of prepend(0, [1])) { actual.push(_)...
syrflover/iterator-helper
deno/lib/utils/mod.ts
export * from './$.ts'; export * from './curry.ts'; export * from './flip.ts'; export * from './id.ts'; export * from './pipe.ts';
syrflover/iterator-helper
src/types/functions/equal.ts
<gh_stars>1-10 export type EqualFn<T> = (a: T, b: T) => boolean | Promise<boolean>;
syrflover/iterator-helper
src/methods/forEach_test.ts
<reponame>syrflover/iterator-helper<gh_stars>1-10 import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { iterator } from '../mod.ts'; Deno.test('forEach() [1,2,3,4,5,6]', async () => { const a = [1, 2, 3, 4, 5, 6]; let actual = 0; const expected = a.length; const r = await...
syrflover/iterator-helper
src/methods/enumerate.ts
import { getLogger } from '../logger.ts'; import { pair, Pair } from '../types/mod.ts'; import { next_async } from '../lib/iterable/mod.ts'; import { scan } from './scan.ts'; const logger = await getLogger('methods/enumerate'); async function* _enumerate_impl_fn<T>(iter: AsyncIterable<T>): AsyncIterable<Pair<numbe...
syrflover/iterator-helper
src/methods/stepBy.ts
<filename>src/methods/stepBy.ts import { getLogger } from '../logger.ts'; import { _curry } from '../lib/utils/mod.ts'; const logger = await getLogger('methods/stepBy'); async function* _step_by_impl_fn<T>(step: number, iter: AsyncIterable<T>): AsyncIterable<T> { logger.trace('stepBy()'); let current_step = ...
syrflover/iterator-helper
src/types/functions/fold.ts
<reponame>syrflover/iterator-helper export type FoldFn<A, B> = (accumulator: B, elem: A) => B | Promise<B>; // export type FoldrFn<A, B> = (elem: A, accumulator: B) => B | Promise<B>;
syrflover/iterator-helper
src/methods/unzip.ts
import { getLogger } from '../logger.ts'; import { Pair, pair } from '../types/mod.ts'; import { append, sequence } from '../lib/iterable/mod.ts'; import { fold } from './fold.ts'; const logger = await getLogger('methods/unzip'); async function _unzip_impl_fn<T, U>(iter: AsyncIterable<Pair<T, U>>): Promise<Pair<As...
syrflover/iterator-helper
deno/lib/utils/id.ts
export const id = <T>(e: T): T => e;
syrflover/iterator-helper
src/types/functions/key.ts
export type KeyFn<T, K> = (elem: T) => K | Promise<K>;
syrflover/iterator-helper
src/methods/fold1_test.ts
<reponame>syrflover/iterator-helper import { assert, assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { iterator } from '../mod.ts'; Deno.test('fold1() sum', async () => { const a = iterator([1, 2, 3, Promise.resolve(4), 5]); const actual = await a.fold1((acc, e) => acc + e); const ...
syrflover/iterator-helper
deno/methods/max.ts
import { compare } from "../lib/compare/mod.ts"; import { maxBy } from "./maxBy.ts"; export function max<T>(iter: AsyncIterable<T>): Promise<T | undefined> { return maxBy(compare, iter); }
syrflover/iterator-helper
src/methods/map_test.ts
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { iterator } from '../mod.ts'; Deno.test('map() [1,2,3,4,5] -> [2,3,4,5,6]', async () => { const a = iterator([1, 2, 3, 4, 5]); const actual: number[] = []; const expected = [2, 3, 4, 5, 6]; for await (const _ of a.map((...
syrflover/iterator-helper
deno/methods/product.ts
<reponame>syrflover/iterator-helper<filename>deno/methods/product.ts import { fold } from "./fold.ts"; export function product(iter: AsyncIterable<number>): Promise<number> { return fold((acc, e) => acc * e, 1, iter); }
syrflover/iterator-helper
src/methods/collect.ts
<reponame>syrflover/iterator-helper import { getLogger } from '../logger.ts'; import { fold } from './fold.ts'; const logger = await getLogger('methods/collect'); export function collect<T>(iter: AsyncIterable<T>): Promise<T[]> { logger.trace('collect()'); return fold((acc: T[], e: T) => [...acc, e], [] as T...
syrflover/iterator-helper
deno/methods/find.ts
<filename>deno/methods/find.ts import type { PredicateFn } from "../types/functions/mod.ts"; import { _curry } from "../lib/utils/mod.ts"; async function _find_impl_fn<T>( predicate: PredicateFn<T>, iter: AsyncIterable<T>, ): Promise<T | undefined> { for await (const elem of iter) { const condition = await ...
syrflover/iterator-helper
deno/lib/iterable/append.ts
export async function* append<T>(x: T, xs: Iterable<T> | AsyncIterable<T>): AsyncIterable<T> { yield* xs; yield x; }
syrflover/iterator-helper
deno/methods/skipWhile.ts
import type { PredicateFn } from "../types/functions/mod.ts"; import { next_async, prepend } from "../lib/iterable/mod.ts"; import { _curry } from "../lib/utils/mod.ts"; async function* _skip_while_impl_fn<T>( predicate: PredicateFn<T>, iter: AsyncIterable<T>, ): AsyncIterable<T> { while (true) { const { do...
syrflover/iterator-helper
src/lib/utils/pipe_test.ts
<filename>src/lib/utils/pipe_test.ts import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { pipe } from './mod.ts'; Deno.test('pipe()', async () => { const fn = pipe( (a: number) => a + 1, async (a) => a * 3, (a) => a / 2, ); const actual = await fn(1); ...
syrflover/iterator-helper
src/methods/flatten.ts
<gh_stars>1-10 import type { Flatten } from '../types/mod.ts'; import { getLogger } from '../logger.ts'; import { isIterable, isAsyncIterable } from '../types/guards/mod.ts'; const logger = await getLogger('methods/flatten'); async function* _flatten_impl_fn<T>(iter: AsyncIterable<T>): AsyncIterable<Flatten<T>> { ...
syrflover/iterator-helper
src/lib/compare/min_test.ts
<gh_stars>1-10 import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { min } from './mod.ts'; Deno.test('min(100, 1, compare) == 1', async () => { const actual = await min(100, 1); const expected = 1; assertEquals(actual, expected); }); Deno.test('min(1, 100, compare) == 1', as...
syrflover/iterator-helper
deno/methods/chain.ts
import { _curry } from "../lib/utils/mod.ts"; async function* _chain_impl_fn<T>( other: Iterable<T | Promise<T>> | AsyncIterable<T | Promise<T>>, iter: AsyncIterable<T>, ): AsyncIterable<T> { yield* iter; yield* other; } export interface Chain { <T>( other: Iterable<T | Promise<T>> | AsyncIterable<T | P...
syrflover/iterator-helper
src/methods/minBy_test.ts
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { Ord } from '../types/mod.ts'; import { compare } from '../lib/compare/mod.ts'; import { iterator } from '../mod.ts'; function _compare<T>(a: T, b: T): Ord { if (a > b) { return Ord.Less; } if (a < b) { retur...
syrflover/iterator-helper
src/methods/take_test.ts
<gh_stars>1-10 import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { iterator } from '../mod.ts'; Deno.test('take(4)', async () => { const a = iterator([1, 2, 3, 4, 5, 6, 7, 8]); const actual: number[] = []; const expected = [1, 2, 3, 4]; const it = a.take(4); for aw...
syrflover/iterator-helper
deno/methods/takeWhile.ts
<gh_stars>1-10 import type { PredicateFn } from "../types/functions/mod.ts"; import { _curry } from "../lib/utils/mod.ts"; async function* _take_while_impl_fn<T>( predicate: PredicateFn<T>, iter: AsyncIterable<T>, ): AsyncIterable<T> { for await (const elem of iter) { const condition = await predicate(elem)...
syrflover/iterator-helper
deno/lib/utils/$.ts
<filename>deno/lib/utils/$.ts<gh_stars>1-10 import { sequence } from '../iterable/mod.ts'; import { fold } from '../../methods/mod.ts'; export function $<P, R1>(p: P | Promise<P>, f0: (p: P) => R1 | Promise<R1>): Promise<R1>; export function $<P, R1, R2>(p: P | Promise<P>, f0: (p: P) => R1 | Promise<R1>, f1: (r0: R1)...
syrflover/iterator-helper
deno/mod.ts
<gh_stars>1-10 export type { AsyncIterator_, ToAsyncIterator, IAsyncIterator_, IAsyncIterator_number, IAsyncIterator_zip } from './iterator.ts'; export { iterator } from './iterator.ts'; export * from './methods/mod.ts';
syrflover/iterator-helper
src/methods/partition.ts
<reponame>syrflover/iterator-helper<gh_stars>1-10 import type { PredicateFn } from '../types/functions/mod.ts'; import { getLogger } from '../logger.ts'; import { pair, Pair } from '../types/mod.ts'; import { append, sequence } from '../lib/iterable/mod.ts'; import { _curry } from '../lib/utils/mod.ts'; import { fo...
syrflover/iterator-helper
src/types/functions/compare.ts
import type { Ord } from '../mod.ts'; export type CompareFn<T> = (a: T, b: T) => Ord | Promise<Ord>;
syrflover/iterator-helper
deno/methods/count.ts
<gh_stars>1-10 import { fold } from "./fold.ts"; // [a] -> Int export function count<T>(iter: AsyncIterable<T>): Promise<number> { return fold((count_: number) => count_ + 1, 0, iter); }
syrflover/iterator-helper
src/types/pair.ts
export type Pair<T, U> = [T, U]; export function pair<T, U>(first: T, second: U): Pair<T, U> { return [first, second]; }
syrflover/iterator-helper
deno/methods/cycle.ts
async function* _cycle_impl_fn<T>(iter: AsyncIterable<T>): AsyncIterable<T> { const r: T[] = []; for await (const elem of iter) { yield elem; r.push(elem); } while (true) { yield* r; } } export function cycle<T>(iter: AsyncIterable<T>): AsyncIterable<T> { return _cycle_impl_fn(iter); }
syrflover/iterator-helper
src/types/guards/isAsyncIterable.ts
import { isFunction } from './isFunction.ts'; import { isNull } from './isNull.ts'; export function isAsyncIterable(a: any): a is AsyncIterable<any> { return isNull(a) ? false : isFunction(a[Symbol.asyncIterator]); }
syrflover/iterator-helper
src/methods/nth.ts
<filename>src/methods/nth.ts import { getLogger } from '../logger.ts'; import { _curry } from '../lib/utils/mod.ts'; const logger = await getLogger('methods/nth'); async function _nth_impl_fn<T>(n: number, iter: AsyncIterable<T>): Promise<T | undefined> { logger.trace('nth()'); let current = 0; for awai...
syrflover/iterator-helper
src/lib/compare/maxBy_test.ts
<reponame>syrflover/iterator-helper import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { id } from '../utils/mod.ts'; import { compare, maxBy } from './mod.ts'; Deno.test('maxBy(100, 1, compare) == 100', async () => { const actual = await maxBy(id, compare, 100, 1); const expected...
syrflover/iterator-helper
src/types/functions/predicate.ts
<gh_stars>1-10 export type PredicateFn<T> = (elem: T) => boolean | Promise<boolean>;
syrflover/iterator-helper
src/methods/skip_test.ts
<filename>src/methods/skip_test.ts<gh_stars>1-10 import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { iterator } from '../mod.ts'; Deno.test('skip(4)', async () => { const a = iterator([1, 2, 3, 4, 5, 6, 7, 8]); const actual: number[] = []; const expected = [5, 6, 7, 8]; ...
syrflover/iterator-helper
src/lib/compare/compare_test.ts
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { Ord } from '../../types/mod.ts'; import { compare } from './mod.ts'; Deno.test('compare(100, 1) == Greater', () => { const actual = compare(100, 1); const expected = Ord.Greater; assertEquals(actual, expected); }); Deno.te...
syrflover/iterator-helper
src/methods/min.ts
<gh_stars>1-10 import { getLogger } from '../logger.ts'; import { compare } from '../lib/compare/mod.ts'; import { minBy } from './minBy.ts'; const logger = await getLogger('methods/min'); export function min<T>(iter: AsyncIterable<T>): Promise<T | undefined> { logger.trace('min()'); return minBy(compare, i...
syrflover/iterator-helper
src/types/guards/isFunction.ts
import { isNull } from './isNull.ts'; export function isFunction(a: any): a is Function { return isNull(a) ? false : a.constructor === Function; }
syrflover/iterator-helper
src/methods/reverse.ts
import { getLogger } from '../logger.ts'; import { fold } from './fold.ts'; import { prepend, sequence } from '../lib/iterable/mod.ts'; import { flip } from '../lib/utils/mod.ts'; const logger = await getLogger('methods/reverse'); async function* _reverse_impl_fn<T>(iter: AsyncIterable<T>): AsyncIterable<T> { l...
syrflover/iterator-helper
src/methods/maxByKey_test.ts
<reponame>syrflover/iterator-helper import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { Ord } from '../types/mod.ts'; import { iterator } from '../mod.ts'; function _cmp<T>(a: T, b: T): Ord { if (a > b) { return Ord.Less; } if (a < b) { return Ord.Greater; ...
syrflover/iterator-helper
src/methods/nubBy_test.ts
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { iterator } from '../mod.ts'; Deno.test(`nubBy() ['a', 'bb', 'ccc']`, async () => { const a = iterator(['a', 'bb', 'b', 'ccc', 'aa', 'cc', 'aaa']); const actual: string[] = []; const expected = ['a', 'bb', 'ccc']; const...
syrflover/iterator-helper
deno/lib/iterable/mod.ts
<gh_stars>1-10 export * from './append.ts'; export * from './init.ts'; export * from './initLast.ts'; export * from './prepend.ts'; // convert export * from './toIterable.ts'; export * from './toAsyncIterable.ts'; // util export * from './next.ts';
syrflover/iterator-helper
src/methods/find.ts
<gh_stars>1-10 import type { PredicateFn } from '../types/functions/mod.ts'; import { getLogger } from '../logger.ts'; import { _curry } from '../lib/utils/mod.ts'; const logger = await getLogger('methods/find'); async function _find_impl_fn<T>(predicate: PredicateFn<T>, iter: AsyncIterable<T>): Promise<T | undefin...
syrflover/iterator-helper
src/methods/all.ts
import type { PredicateFn } from '../types/functions/mod.ts'; import { getLogger } from '../logger.ts'; import { _curry } from '../lib/utils/mod.ts'; const logger = await getLogger('methods/all'); async function _all_impl_fn<T>(fn: PredicateFn<T>, iter: AsyncIterable<T>): Promise<boolean> { logger.trace('all()'...
syrflover/iterator-helper
src/lib/compare/max_test.ts
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { max } from './mod.ts'; Deno.test('max(100, 1, compare) == 100', async () => { const actual = await max(100, 1); const expected = 100; assertEquals(actual, expected); }); Deno.test('max(1, 100, compare) == 100', async () =>...
syrflover/iterator-helper
src/lib/utils/$_test.ts
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { $ } from './mod.ts'; Deno.test('$()', async () => { const actual = await $( 1, (a) => a + 1, (a) => a * 3, async (a) => a / 2, ); const expected = 3; assertEquals(actual, expected); });
syrflover/iterator-helper
src/lib/utils/curry_test.ts
<gh_stars>1-10 import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { curry } from './mod.ts'; Deno.test('curry() add a b', () => { const add = (a: number, b: number) => a + b; const curried = curry(add); const add_2 = curried(2); assertEquals(add_2(5), 7); }); Deno.test...
syrflover/iterator-helper
src/methods/enumerate_test.ts
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { pair, Pair } from '../types/mod.ts'; import { iterator } from '../mod.ts'; Deno.test(`enumerate(['a', 'b', 'c', 'd', 'e'])`, async () => { const a = iterator(['a', 'b', 'c', 'd', 'e']); const actual: Pair<number, string>[] = []...
syrflover/iterator-helper
deno/methods/flatMap.ts
<reponame>syrflover/iterator-helper import type { Flatten } from "../types/mod.ts"; import type { MapFn } from "../types/functions/mod.ts"; import { _curry } from "../lib/utils/mod.ts"; async function* _flat_map_impl_fn< T, R extends Iterable<any> | AsyncIterable<any>, >( fn: MapFn<T, R>, iter: AsyncIterable<...
syrflover/iterator-helper
src/methods/last.ts
import { getLogger } from '../logger.ts'; import { fold } from './fold.ts'; const logger = await getLogger('methods/last'); // [a] -> Maybe a export function last<T>(iter: AsyncIterable<T>): Promise<T | undefined> { logger.trace('last()'); return fold((_, e) => e, undefined as T | undefined, iter); }
syrflover/iterator-helper
src/methods/nub_test.ts
<reponame>syrflover/iterator-helper import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'; import { iterator } from '../mod.ts'; Deno.test('nub() [1, 2, 3, 4, 5, 6]', async () => { const a = iterator([1, 2, 1, 3, 2, 4, 3, 5, 4, 1, 5, 6]); const actual: number[] = []; const expected = [1...