From 173b249d9a91d8fee7c3cc18946e8fda188295c2 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 8 Jan 2022 17:33:10 +0530 Subject: refactor: creates constructors for expr adt --- src/utils.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/utils.ts') diff --git a/src/utils.ts b/src/utils.ts index 9c4c97b..6591050 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -7,3 +7,18 @@ export const match = (pattern: { [key in K | '_']: () => R }) => (k: K): R => (pattern[k] || pattern._)() + +type Tag = { tag: N; value: V } +export type Union = { [N in keyof T]: Tag }[keyof T] + +export const constructors = >(): { + [N in keyof T]: (value: T[N]) => Union // Tag +} => + new Proxy( + {}, + { + get(_, k) { + return (value: any) => ({ tag: k, value }) + }, + } + ) as any -- cgit v1.3.1