Control Statement that can return result is cool. It can reduce ugly code. Some other libs have done this but they are too complicated for our need.
at least ES2015
yarn add @ag1/return_switchimport { returnSwitch } from '@ag1/return_switch';const foo = returnSwitch<string>('foo')([
['foo', 'foo'], // matched
[true, 'bar'],
]);
console.log(foo); // fooconst bar = returnSwitch<string>('bar')([
['foo', 'foo'],
[true, 'bar'], // default
]);
console.log(bar); // barconst lorem = returnSwitch<string>('lorem')([
['foo', 'foo'],
['bar', 'bar'],
]); // NO_MATCH, throw erroryarn test