Skip to content

Instantly share code, notes, and snippets.

@kylecorbelli
Last active June 22, 2018 14:40
Show Gist options
  • Save kylecorbelli/e7990295d88250cdf19121bc7b80b04b to your computer and use it in GitHub Desktop.
Save kylecorbelli/e7990295d88250cdf19121bc7b80b04b to your computer and use it in GitHub Desktop.
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