Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why was "complement" used as a name for the function in ramda.js

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?

like image 826
robstarbuck Avatar asked Aug 02 '18 21:08

robstarbuck


People also ask

What is Ramda in JavaScript?

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.

What is compose in ramda?

compose Function Performs right-to-left function composition. The rightmost function may have any arity; the remaining functions must be unary.

Why should I use ramda?

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.


1 Answers

“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.

like image 89
Scott Christopher Avatar answered Nov 15 '22 10:11

Scott Christopher