I think perhaps there's some confusion here (beyond what customcommander rightly points out about the type of constraint
.)
One of the features Ramda tries to offer is to allow us to program with expressions rather than statements. Especially concerning are control-flow statements. But a statement that looks like this:
let foo
if (condition) {
foo = 'bar'
} else {
foo = 'baz'
}
already has a standard expression form:
const foo = condition ? 'bar' : 'baz'
Ramda does not really try to offer an alternative to this. But there is another way we might try to use if
:
let foo
if (test(val)) {
foo = bar(val)
} else {
foo = baz(val)
}
Here, when working with functions, Ramda offers a convenient shorthand:
const getFoo = ifElse(test, bar, baz)
// ... later
const foo = getFoo(val)
(And if you just want to return val
in the case the test fails, you can use the shorthand:
const foo = when(test, bar)
Or if you want val
when the test succeeds, you can do
const foo = unless(test, baz)
)
While it might be slightly more expressive to turn the code into
const foo = ifElse(test, bar, baz)(val)
That's not the main point. The rationale for ifElse
is to use it in creating the reusable function ifElse(test, bar, baz)
. (cond
is just the same, just offering a sequence of condition-consequent pairs instead of one if
and one else
.)
Note one important feature to this: the test function, the function to run if it's true, and the one to run if it's false all have the same signature. If one of them takes three parameters, then they all should accept three parameters. And while the test should return a boolean, the other two can have any return type, but each should have the same return type as the other.
So one can use a thunk, as you try with () => constraintElement.click()
, it is mostly a misuse of the Ramda feature. It probably gains you nothing in your code.
It's still not clear what you're trying to do with the conversion from an if
statement to ifElse
or cond
. Please feel free to add an update to your question explaining more fully what you're trying to do, and what problem you're trying to solve with this conversion, someone will probably be able to offer some help. But make sure you clarify what constraint
and constraintElement
are and what waitForElementToBeClickable
resolves to. Right now it's fairly confusing.