cleanup, patterns

This commit is contained in:
Oli Sturm
2026-04-27 13:08:40 +01:00
parent d0c9466170
commit 3194231879
8 changed files with 66 additions and 36 deletions
+10
View File
@@ -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;