Skip to content

Commit

Permalink
feat(transducers): add noop() xform, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jan 27, 2018
1 parent 44db970 commit 7b21aa6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/transducers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,12 @@ is done dynamically via for loop.

#### `compR(rfn: Reducer<any, any>, fn: (acc, x) => any): Reducer<any, any>`

Helper function to build reducers.
Helper function to compose reducers.

#### `iterator<A, B>(tx: Transducer<A, B>, xs: Iterable<A>): IterableIterator<B>`

Similar to `transduce()`, but emits results as ES6 iterator (and hence doesn't use a reduction function).
Similar to `transduce()`, but emits results as ES6 iterator (and hence doesn't
use a reduction function).

#### `reduce<A, B>(rfn: Reducer<A, B>, acc: A, xs: Iterable<B>): A`

Expand Down Expand Up @@ -596,6 +597,8 @@ reducer and optional initial accumulator/result.

#### `multiplexObj<A, B>(xforms: IObjectOf<Transducer<A, any>>, rfn?: Reducer<B, [PropertyKey, any]>): Transducer<A, B>`

#### `noop<T>(): Transducer<T, T>`

#### `padLast<T>(n: number, fill: T): Transducer<T, T>`

#### `partition<T>(size: number, step?: number, all?: boolean): Transducer<T, T[]>`
Expand Down
1 change: 1 addition & 0 deletions packages/transducers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export * from "./xform/mapcat";
export * from "./xform/moving-average";
export * from "./xform/multiplex";
export * from "./xform/multiplex-obj";
export * from "./xform/noop";
export * from "./xform/pad-last";
export * from "./xform/partition-by";
export * from "./xform/partition-of";
Expand Down
10 changes: 10 additions & 0 deletions packages/transducers/src/xform/noop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Transducer } from "../api";

/**
* No-op / pass-through transducer, essentially the same as:
* `map(identity)`, but faster. Useful for testing and/or to
* keep existing values in a `multiplex()` tuple lane.
*/
export function noop<T>(): Transducer<T, T> {
return (rfn) => rfn;
}

0 comments on commit 7b21aa6

Please sign in to comment.