Ramda: Use many parameters in operator R.or

Created on 23 May 2019  路  1Comment  路  Source: ramda/ramda

Hello everyone, I'm beginning in use the Ramdajs and this is amazing lib to work with paradigm functional programming in JavaScript.

So I was using the operator R.or, but at the moment, the operator use only two parameters, for example:

R.or(optionA, optionB);

I don't know if it's possible, but I think is a great feature, allow the operator R.or use the many parameters, for example:

R.or(optionA, optionB, optionC, optionD, ...);

Most helpful comment

@lhenriquegomescamilo: Ramda avoids that sort of signature almost everywhere (I'm looking at you, pipe* and compose*!) for very important reasons.

Ramda is designed around function composition, and to support that curries pretty much everything. But curried functions really don't work with variadic input. So that's really not possible within the Ramda philosophy.

But it's very easy to wrap this in your own function:

const orAny = reduce(or, false)
const andAll = reduce(and, true)

These take array of values. If you really want that variadic signature, you can just add unapply (unapply(reduce(or, false)).)

>All comments

@lhenriquegomescamilo: Ramda avoids that sort of signature almost everywhere (I'm looking at you, pipe* and compose*!) for very important reasons.

Ramda is designed around function composition, and to support that curries pretty much everything. But curried functions really don't work with variadic input. So that's really not possible within the Ramda philosophy.

But it's very easy to wrap this in your own function:

const orAny = reduce(or, false)
const andAll = reduce(and, true)

These take array of values. If you really want that variadic signature, you can just add unapply (unapply(reduce(or, false)).)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tylerlong picture tylerlong  路  3Comments

woss picture woss  路  3Comments

Antontelesh picture Antontelesh  路  3Comments

ldk18501 picture ldk18501  路  3Comments

makarkotlov picture makarkotlov  路  3Comments