cleanup, patterns
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user