Conditional expression that enforces exhaustive returns without early returns. Similar to Scala's if/else expressions that always return a value.
const discount = Cond.of<number>() .when(isPremiumMember, 0.2) .elseWhen(isRegularMember, 0.1) .else(0) Copy
const discount = Cond.of<number>() .when(isPremiumMember, 0.2) .elseWhen(isRegularMember, 0.1) .else(0)
// Chaining multiple conditionsconst status = Cond.of<string>() .when(response.status >= 500, "Server Error") .elseWhen(response.status >= 400, "Client Error") .elseWhen(response.status >= 200, "Success") .else("Unknown") Copy
// Chaining multiple conditionsconst status = Cond.of<string>() .when(response.status >= 500, "Server Error") .elseWhen(response.status >= 400, "Client Error") .elseWhen(response.status >= 200, "Success") .else("Unknown")
Terminal else clause - required to get the result
Add an else-if condition
Get the result if a condition was met, throws if no condition met
Add an if condition
Conditional expression that enforces exhaustive returns without early returns. Similar to Scala's if/else expressions that always return a value.
Example
Example