arachnea is a JavaScript library that allows you to perform efficient array operations using a fluent API approach inspired by the agility and efficiency of spiders.
- Map: Transform each element of an array using a provided function.
- Filter: Filter elements of an array based on a provided condition.
- Reduce: Reduce an array to a single value based on a provided accumulator and transformation function.
- Find: Find the first element in the array that meets the given condition.
- Remove: Remove the first element in the array that meets the given condition.
- ForEach: Execute a provided function once for each array element.
You can install arachnea via npm or yarn:
npm install arachnea
# or yarn
yarn add arachnea
import arachnea from "arachnea";
const numbers = [1, 2, 3, 4, 5];
arachnea(numbers).forEach((num) => {
console.log(num * 2); // Example of using forEach
});
const sumOfSquares = arachnea(numbers)
.map((num) => num * num)
.reduce((acc, num) => acc + num, 0);
console.log(sumOfSquares); // Output: 55
const oddNumbers = arachnea(numbers)
.filter((num) => num % 2 !== 0)
.collect();
console.log(oddNumbers); // Output: [1, 3, 5]
const remove4 = arachnea(numbers)
.map((num) => num * num)
.remove(4)
.collect();
console.log(remove4); // Output: [1, 9, 16, 25]
const greaterThanTwentyFour = arachnea(numbers)
.map((num) => num * num)
.find((num) => num > 24);
console.log(greaterThanTwentyFour); // Output: 25
const result = arachnea(numbers)
.filter((num) => num > 2)
.map((num) => num * 3)
.reduce((acc, num) => acc + num, 0);
console.log(result); // Output: 39
Transforms each element of the array using the provided transformer function.
Filters elements of the array based on the provided boolean condition function.
Reduces the array to a single value using the provided reducer function and initial value.
Removes the first element in the array that meets the given condition or is equal to the given parameter.
Finds the first element in the array that meets the given condition or is equal to the given parameter.
Executes a provided function once for each array element.
Collects the elements after applying all transformations and filters, returning them as an array.
- Combine successive filter operations into a single operation.
- Document
actionsLoop
for custom terminating operation injection. - Improve the performance of atomic operations.
- Add sorting, flattening functionality.
- Enhance performance optimizations.
- Implement error handling for edge cases.
Contributions are welcome! Please fork the repository and submit a pull request.