Created
December 15, 2019 10:59
-
-
Save WimJongeneel/a5545bbd444d24074a51e8c9bbe50a4f 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 Option<a> = { kind: 'none' } | { kind: 'some', value: a } | |
let val: Option<string> = { kind: 'some', value: 'hello' } | |
// Conditinal way of geting the value | |
if(val.kind == 'some') return val.value | |
// Pattern matching way of geting the value | |
match(val) | |
.with({ kind: 'some' }, o => o.value) // TypeError! | |
.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment