Skip to content

Instantly share code, notes, and snippets.

@odiak
Created January 10, 2017 07:53
Show Gist options
  • Save odiak/8e4967834aca6f2adf54baa403588bca to your computer and use it in GitHub Desktop.
Save odiak/8e4967834aca6f2adf54baa403588bca to your computer and use it in GitHub Desktop.
sealed class Either<out L, out R> {
class Left<out T>(val value: T) : Either<T, Nothing>() {
override fun equals(other: Any?): Boolean =
other is Left<*> && other.value == value
override fun hashCode(): Int = value?.hashCode() ?: 0
override fun toString(): String = "Left($value)"
}
class Right<out T>(val value: T) : Either<Nothing, T>() {
override fun equals(other: Any?): Boolean =
other is Right<*> && other.value == value
override fun hashCode(): Int = value?.hashCode() ?: 0
override fun toString(): String = "Right($value)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment