I understand the use of ramda's complement function which inverts the return of a predicate. What I can't get my head around is why "complement" was used as a name.
const invertPredicate = R.complement(R.identity)
invertPredicate(false) //true
Could someone please give some insight into this?
Ramda is a practical functional library for JavaScript programmers. The library focuses on immutability and side-effect free functions. Ramda functions are also automatically curried, which allows to build up new functions from old ones simply by not supplying the final parameters.
compose Function Performs right-to-left function composition. The rightmost function may have any arity; the remaining functions must be unary.
What makes Ramda great is that their functions are automatically curried, which allows us to quickly build up sequences of small and straightforward functions or old functions that we already have created.
“In set theory, the complement of a set A refers to elements not in A”
https://en.m.wikipedia.org/wiki/Complement_(set_theory)
So R.complement
will produce a predicate for all values that don’t satisfy the provided predicate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With