ramda-adjunct icon indicating copy to clipboard operation
ramda-adjunct copied to clipboard

condOr

Open Undistraction opened this issue 6 years ago • 3 comments

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

REPL

Undistraction avatar Apr 05 '18 09:04 Undistraction

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.

guillaumearm avatar Apr 22 '18 15:04 guillaumearm

@char0n You OK to elevate this to a feature?

Undistraction avatar Apr 22 '18 16:04 Undistraction

Yes. This is legit and practical

char0n avatar Oct 03 '18 19:10 char0n