aboutsummaryrefslogtreecommitdiff
path: root/src/util.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.ts')
-rw-r--r--src/util.ts4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/util.ts b/src/util.ts
new file mode 100644
index 0000000..0b60bb1
--- /dev/null
+++ b/src/util.ts
@@ -0,0 +1,4 @@
+
+export const match = <K extends string, R>(k: K | undefined, pattern: { [key in K | '_']: () => R }) =>
+ k && pattern[k] ? pattern[k]() : pattern._()
+