Created
December 15, 2019 10:50
-
-
Save WimJongeneel/1f51443f0e41446f6d06268d5e7c7108 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Pattern<a> = { [ k in keyof a ]?: Pattern<a[k]> } | |
const match_pattern = <a>(value: a, pattern: Pattern<a>) => typeof(value) != 'object' | |
? value === pattern | |
: Object.keys(pattern).every(k => pattern[k] == undefined ? false : match_pattern(value[k], pattern[k])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment