Skip to content

Latest commit

 

History

History
212 lines (151 loc) · 3.79 KB

document.md

File metadata and controls

212 lines (151 loc) · 3.79 KB

document

combine

combine combines some transform methods to a transform method.

function combine(...tfs: TransduceFunction[]): TransduceFunction

transform method

Collection<A> => Collection<B>

map

function map<T, K>(f: Map<T, K>): TransduceFunction<T, K>

scan

function scan<T, K>(f: Scan<T, K>, v: K): TransduceFunction<T, K>

filter

function filter<T>(f: Predicate<T>): TransduceFunction<T, T>

remove

function remove<T>(f: Predicate<T>): TransduceFunction<T, T>

take

function take<T>(n: number): TransduceFunction<T, T>

takeWhile

function takeWhile<T>(f: Predicate<T>): TransduceFunction<T, T>

skip

function skip<T>(n: number): TransduceFunction<T, T>

skipWhile

function skipWhile<T>(f: Predicate<T>): TransduceFunction<T, T>

partition

function partition<T>(n: number): TransduceFunction<T, T[]>

partitionBy

function partitionBy<T>(f: Map<T, any>): TransduceFunction<T, T[]>

flatten

function flatten<T>(): TransduceFunction<T[], T>

groupBy

function groupBy<T, Key, K>(f: Group<T, Key>, gr: GroupByReduce<T, Key, K>): TransduceFunction<T, K>

GroupByReduce

function groupByReduce<T, Key, K>(k: Key): TransduceHandler<T, K>

Get transduce handler by each-once/transduce.

import * as Transduce from "each-once/transduce";

usage

import { combine, groupBy, take, foreach } from "each-once";
import * as Transduce from "each-once/transduce";

const s = function* () {
  while (true) {
    yield Math.random() * 10;
  }
};

foreach(
  (x: number[]) => console.log(x),
  combine(
    take<number>(100),
    groupBy(
      (x: number) => Math.floor(x),
      (key) => Transduce.toArray(take<number>(10))
    )
  )
)(s());

reduce method

Collection<A> => B

count

function count<T>(tf: TransduceFunction<T, any>): (iter: Iterable<T>) => number

include

function include<T, K>(v: K, tf: TransduceFunction<T, K>): (iter: Iterable<T>) => boolean

every

function every<T, K>(f: Predicate<K>, tf: TransduceFunction<T, K>): (iter: Iterable<T>) => boolean

some

function some<T, K>(f: Predicate<K>, tf: TransduceFunction<T, K>): (iter: Iterable<T>) => boolean

first

function first<T, K>(tf: TransduceFunction<T, K>): (iter: Iterable<T>) => K | void

last

function last<T, K>(tf: TransduceFunction<T, K>): (iter: Iterable<T>) => K | void

reduce

function reduce<T, K, R>(rf: ReduceFunction<K, R>, v: R, tf: TransduceFunction<T, K>): (iter: Iterable<T>) => R

foreach

function foreach<T, K>(f: Action<K>, tf: TransduceFunction<T, K>): (iter: Iterable<T>) => void

toArray

function toArray<T, K>(tf: TransduceFunction<T, K>): (iter: Iterable<T>) => K[]

async

Use async by each-once/async and each-once/async/transduce