score:0

Accepted answer

if you are trying to use the same expressions for cond1, cond2, ... in both snippets, then i understand the problem.

ramda's cond takes predicate functions, not boolean expressions. and it returns a function that you need to call to do anything useful.

thus this expression

cond ([
  [predicate1, consequent1],
  [predicate2, consequent2],
  [predicate3, consequent3],
  [t, finalguard],
])

takes functions for both the predicates and the consequents. it passes the same arguments to each. it's essentially equivalent to

(...args) =>
  predicate1 (...args)
    ? consequent1 (...args)
  : predicate2 (...args)
    ? consequent2 (...args)
  : predicate3 (...args)
    ? consequent3 (...args)
  : t (...args)
    ? finalguard (...args) 
    : undefined  // won't hit this since the final predicate always returns `true`

it sounds like this would explain your problem. if not, please post additional details.

(disclaimer: i'm a ramda author.)


Related Query

More Query from same tag