Skip to content

Instantly share code, notes, and snippets.

@mlhaufe
Last active January 16, 2017 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlhaufe/5d5a098cb6cae372ee7f7e89c4c8a031 to your computer and use it in GitHub Desktop.
Save mlhaufe/5d5a098cb6cae372ee7f7e89c4c8a031 to your computer and use it in GitHub Desktop.
Coproducts
// data Either a b = Left a | Right b
abstract class Either<A, B> {
constructor(public value: A | B) { }
}
// Inject Left
// inl a
class Left<A> extends Either<A, never>{
constructor(value: A) { super(value) }
}
// Inject Right
// inr a
class Right<B> extends Either<never, B>{
constructor(value: B){ super(value) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment