diff options
| author | Akshay Nair <phenax5@gmail.com> | 2022-01-08 17:33:10 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2022-01-08 17:33:10 +0530 |
| commit | 173b249d9a91d8fee7c3cc18946e8fda188295c2 (patch) | |
| tree | 65e1435798cc652101e9a0feefedbe3b3ccacc71 /src/utils.ts | |
| parent | 6639605b395ceb1355c95e06ff0e1470adc54101 (diff) | |
| download | elxr-173b249d9a91d8fee7c3cc18946e8fda188295c2.tar.gz elxr-173b249d9a91d8fee7c3cc18946e8fda188295c2.zip | |
refactor: creates constructors for expr adt
Diffstat (limited to 'src/utils.ts')
| -rw-r--r-- | src/utils.ts | 15 |
1 files changed, 15 insertions, 0 deletions
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 = <R, K extends string>(pattern: { [key in K | '_']: () => R }) => (k: K): R => (pattern[k] || pattern._)() + +type Tag<N, V> = { tag: N; value: V } +export type Union<T> = { [N in keyof T]: Tag<N, T[N]> }[keyof T] + +export const constructors = <T extends Record<string, any>>(): { + [N in keyof T]: (value: T[N]) => Union<T> // Tag<N, T[N]> +} => + new Proxy( + {}, + { + get(_, k) { + return (value: any) => ({ tag: k, value }) + }, + } + ) as any |
