Last active
June 22, 2018 14:40
-
-
Save kylecorbelli/e7990295d88250cdf19121bc7b80b04b 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
enum MaybeType { | |
Just = 'maybe-type__just', | |
Nothing = 'maybe-type__nothing', | |
} | |
interface Just<T> { | |
type: typeof MaybeType.Just | |
value: T | |
} | |
interface Nothing { | |
type: typeof MaybeType.Nothing | |
} | |
type Maybe<T> | |
= Just<T> | |
| Nothing | |
const Nothing = (): Nothing => ({ | |
type: MaybeType.Nothing, | |
}) | |
const Just = <T> (value: T): Just<T> => ({ | |
type: MaybeType.Just, | |
value, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment