let answer;
switch (value) {
case 1:
answer = 'one';
break;
default:
answer = 'forty-two';
}
...
<div>
{answer}
<div/>
|
// The match function call is a expression,
// you can use it directly in jsx
<div>
{match(value)(
[1, 'one'],
[stubTrue, 'forty-two']
)}
<div/>
|
switch (value) {
case _.isArray(value):
doSomething(value);
break;
case _.isNumber(value):
doAnotherThing(value);
break
}
|
// Support for parameters of function types.
// Its return value will be used as the return value of the match function.
match(value)(
[_.isArray,doSomething],
[_.isNumber,doAnotherThing]
)
|
switch (value) {
case 1:
switch (anotherValue) {
case 2:
return 'one then two';
default:
return 'default';
}
default:
return 'default';
}
|
// If the branch does not match (or returns null),
// subsequent branches will continue to be performed
match(value)(
[1,match(anotherValue)(
[2, 'one then two'])
],
[stubTrue, 'default']
);
|