These are chat archives for ramda/ramda
I'm wondering what the best way to handle a public-facing api that needs to accept implicit undefined values:
api() and explicit undefined values:
api(undefined) is? It appears that Ramda treats the two differently when it comes to curried functions:
const f1 = curry(a => toString(a)) f1(undefined) // 'undefined' f1() // returns the curried function f1
Given that I have no control over the input, I need to handle both cases elegantly. It appears that a non-tacit function call irons this out:
const f1 = curry(a => toString(a)) const f2 = v => f1(v) f2(undefined) // 'undefined' f2() // returns the curried function f1
But wondering if there is a better approach?
SiilwynPedr Browne (Gitter): so you want
That's one way to do it, but whether it's the best way really depends on the specifics. As a general rule, currying and optional parameters aren't a great match. A common pattern I use is to create a higher order function that will take in the configuration and return the function that I will use.
const f = (cfg1, cfg2) => (optionalParam) => doStuffWithAllOfIt...
That way you can take the required parameters, and the function that takes an optional parameter doesn't need to be curried.