https://github.com/hyperjump-io/pact
Higher order functions for iterators/generators and async iterators/generators
https://github.com/hyperjump-io/pact
Last synced: 5 months ago
JSON representation
Higher order functions for iterators/generators and async iterators/generators
- Host: GitHub
- URL: https://github.com/hyperjump-io/pact
- Owner: hyperjump-io
- License: mit
- Created: 2019-08-14T01:08:42.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2025-10-20T19:01:19.000Z (8 months ago)
- Last Synced: 2025-11-23T07:22:56.209Z (7 months ago)
- Language: TypeScript
- Homepage: http://pact.hyperjump.io/
- Size: 66.4 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Hyperjump Pact
Hyperjump Pact is a utility library that provides higher order functions for
working with iterators and async iterators.
## Installation
Designed for node.js (ES Modules, TypeScript) and browsers.
```bash
npm install @hyperjump/pact --save
```
## Usage
```javascript
import { pipe, range, map, filter, reduce } from "@hyperjump/pact";
const result = pipe(
range(1, 10),
filter((n) => n % 2 === 0),
map((n) => n * 2),
reduce((sum, n) => sum + n, 0)
);
console.log(result);
```
```javascript
import { pipe, asyncMap, asyncFilter, asyncReduce } from "@hyperjump/pact";
// You can alternatively import the async functions without the prefix
// import { pipe, map, filter, reduce } from "@hyperjump/pact/async";
const asyncSequence = async function* () {
yield 1;
yield 2;
yield 3;
yield 4;
yield 5;
};
for await (const value of asyncSequence()) {
console.log(value);
}
const result = await pipe(
asyncSequence(),
asyncFilter((n) => n % 2 === 0),
asyncMap((n) => n * 2),
asyncReduce((sum, n) => sum + n, 0)
);
console.log(result);
```
## API
https://pact.hyperjump.io
## Contributing
### Tests
Run the tests
```bash
npm test
```
Run the tests with a continuous test runner
```bash
npm test -- --watch
```
[hyperjump]: https://github.com/hyperjump-io/browser
[jref]: https://github.com/hyperjump-io/browser/blob/master/src/json-reference/README.md