ramda-adjunct
ramda-adjunct copied to clipboard
condOr
Is your feature request related to a problem? Please describe.
A version of R.cond
where the original value is returned as the default (instead of undefined
)
Describe the solution you'd like
const condOr = curry((a, v) => {
const aWithDefault = append([T, identity], a)
return cond(aWithDefault)(v)
})
const f = condOr([
[equals(1), always('Was 1')],
[equals(2), always('Was 2')],
[equals(3), always('Was 3')]
])
f(1) // => Was 1
f(2) // => Was 2
f(3) // => Was 3
f(4) // => 4
Describe alternatives you've considered
Additional context
Nice idea, I so much long time declined to use R.cond
when I need R.T
.
I think R.condDefault
will be useful for me.
@char0n You OK to elevate this to a feature?
Yes. This is legit and practical