Files
2026-04-27 13:08:40 +01:00

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;