Skip to content

Instantly share code, notes, and snippets.

@WimJongeneel
Created December 15, 2019 10:50
Show Gist options
  • Save WimJongeneel/1f51443f0e41446f6d06268d5e7c7108 to your computer and use it in GitHub Desktop.
Save WimJongeneel/1f51443f0e41446f6d06268d5e7c7108 to your computer and use it in GitHub Desktop.
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