A functional, declarative, and typesafe library for composing operations on arrays.
The main function that allows you to compose array operations together. Each operation in the pipe must take an array as input and return an array as output.
const lessThan = (num: number) => (arr: number[]) =>
arr.filter((item) => item < num);
const operation = pipe(lessThan(8), lessThan(5));
operation([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
// [1, 2, 3, 4]Combines the results of two array operations, similar to a SET UNION operation.
const greaterThan = (num: number) => (arr: number[]) =>
arr.filter((item) => item > num);
const lessThan = (num: number) => (arr: number[]) =>
arr.filter((item) => item < num);
const operation = union(greaterThan(8), lessThan(5));
operation([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
// [1, 2, 3, 4, 9, 10]Finds common elements between two array operations, similar to a SET INTERSECTION operation.
const greaterThan = (num: number) => (arr: number[]) =>
arr.filter((item) => item > num);
const lessThan = (num: number) => (arr: number[]) =>
arr.filter((item) => item < num);
const operation = intersection(greaterThan(8), lessThan(5));
operation([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
// []- Type Safety: Cannot construct pipes where output types don't match input types
- Array-Specific: Built specifically for array operations
- Composable: Easy to build complex pipelines from simple operations
- Flexible: Works with various data types (numbers, objects, strings, etc.)
Perfect for building:
- Search result pipelines
- Recommendation feeds
- Data transformation chains
- Filter and sort combinations
Run the test suite:
yarn testCheck out the blog post for a detailed explanation of the implementation and use cases.
Contributions are welcome! Please feel free to submit a Pull Request.
To publish a new version:
- Update version in package.json
- Create release notes in
release-notes/v{version}.md - Commit changes
- Run
yarn deploy
This will publish to npm and create a GitHub release with the corresponding release notes.
MIT License