11 lines
297 B
JavaScript
11 lines
297 B
JavaScript
export const match = (...branches) => (value) => {
|
|
for (const [predicate, handler] of branches) {
|
|
if (predicate(value)) return handler(value);
|
|
}
|
|
throw new Error('No matching pattern');
|
|
};
|
|
|
|
export const when = (predicate, handler) => [predicate, handler];
|
|
|
|
export const any = () => true;
|