Absurdum
"if all you have is a hammer, everything looks like a nail" - Maslow's Hammer
In this package, Array.prototype.reduce is the hammer
Why the Funky Name?
It's a play on the latin phrase Reductio ad absurdum
In logic, reductio ad absurdum (Latin for "reduction to absurdity"; or argumentum ad absurdum, "argument to absurdity") is a form of argument which attempts either to disprove a statement by showing it inevitably leads to a ridiculous, absurd, or impractical conclusion, or to prove one by showing that if it were not true, the result would be absurd or impossible.
It is often said that of the big trio map
, filter
, and reduce
, the first two are redundant. In fact, it's trivial to implement both map
and filter
using reduce
.
This library exists to take that concept to an absurd extreme by using reduce
to implement as many different types of functional transforms as possible.
What's the Point?
- It's a challenge
- It's good practice
- It forces you to code/think in a functional manner
- Who cares, it's fun
...and just maybe, new patterns/practice will emerge from pushing reduce
to its limits.
Usage
Import the desired namespace then call the operator from it
import { arrays } from 'absurdum';
const input = ['a', 'b', 'c', 'd'];
const output = arrays.reverse(input);
console.log(output);
CommonJS
A CommonJS bundle is included for backward compatiblity with node <= 13.2
const absurdum = require('absurdum/dist/absurdum.cjs');
API Documentation
Arrays
Objects
Strings