Skip to content

Commit

Permalink
feat(transducers): add peek() xform, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Feb 5, 2020
1 parent 0eff643 commit 26aa228
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/transducers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ package.
yarn add @thi.ng/transducers
```

Package sizes (gzipped): ESM: 7.8KB / CJS: 8.3KB / UMD: 7.5KB
Package sizes (gzipped): ESM: 7.8KB / CJS: 8.4KB / UMD: 7.6KB

## Dependencies

Expand Down Expand Up @@ -964,6 +964,7 @@ tx.transduce(tx.map((x) => x*10), tx.push(), tx.range(4))
- [partitionSort](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/xform/partition-sort.ts)
- [partitionSync](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/xform/partition-sync.ts)
- [partition](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/xform/partition.ts)
- [peek](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/xform/peek.ts)
- [pluck](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/xform/pluck.ts)
- [rename](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/xform/rename.ts)
- [sample](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/xform/sample.ts)
Expand Down
1 change: 1 addition & 0 deletions packages/transducers/README.tpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ tx.transduce(tx.map((x) => x*10), tx.push(), tx.range(4))
- [partitionSort](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/xform/partition-sort.ts)
- [partitionSync](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/xform/partition-sync.ts)
- [partition](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/xform/partition.ts)
- [peek](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/xform/peek.ts)
- [pluck](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/xform/pluck.ts)
- [rename](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/xform/rename.ts)
- [sample](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/xform/sample.ts)
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 @@ -77,6 +77,7 @@ export * from "./xform/partition-of";
export * from "./xform/partition-sort";
export * from "./xform/partition-sync";
export * from "./xform/partition";
export * from "./xform/peek";
export * from "./xform/pluck";
export * from "./xform/rename";
export * from "./xform/sample";
Expand Down
21 changes: 21 additions & 0 deletions packages/transducers/src/xform/peek.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { peek as _peek } from "@thi.ng/arrays";
import { Transducer } from "../api";
import { map } from "./map";

/**
* Transducer version of {@link @thi.ng/api#peek}, i.e. extracts the
* last item of an array.
*
* @example
* ```ts
* [...peek([ [1, 2, 3], [4, 5] ])]
* // [ 3, 5 ]
* ```
*
* @param src -
*/
export function peek<T>(): Transducer<T[], T>;
export function peek<T>(src: Iterable<T[]>): IterableIterator<T>;
export function peek<T>(src?: Iterable<T[]>): any {
return map(_peek, src!);
}

0 comments on commit 26aa228

Please sign in to comment.