Skip to content

Instantly share code, notes, and snippets.

@gantonious
Created February 17, 2019 14:29
Show Gist options
  • Save gantonious/1eccf112ab9ea2eefd641e8a8e8fd5a0 to your computer and use it in GitHub Desktop.
Save gantonious/1eccf112ab9ea2eefd641e8a8e8fd5a0 to your computer and use it in GitHub Desktop.
fun plus(lhs: Any, rhs: Any): Any {
return when (lhs) {
is Short -> {
when (rhs) {
is Byte -> lhs + rhs
is Short -> lhs + rhs
is Int -> lhs + rhs
is Long -> lhs + rhs
is Float -> lhs + rhs
is Double -> lhs + rhs
else -> throw IncompatibleTypesException()
}
}
is Byte -> {
when (rhs) {
is Byte -> lhs + rhs
is Short -> lhs + rhs
is Int -> lhs + rhs
is Long -> lhs + rhs
is Float -> lhs + rhs
is Double -> lhs + rhs
else -> throw IncompatibleTypesException()
}
}
is Int -> {
when (rhs) {
is Byte -> lhs + rhs
is Short -> lhs + rhs
is Int -> lhs + rhs
is Long -> lhs + rhs
is Float -> lhs + rhs
is Double -> lhs + rhs
else -> throw IncompatibleTypesException()
}
}
is Long -> {
when (rhs) {
is Byte -> lhs + rhs
is Short -> lhs + rhs
is Int -> lhs + rhs
is Long -> lhs + rhs
is Float -> lhs + rhs
is Double -> lhs + rhs
else -> throw IncompatibleTypesException()
}
}
is Float -> {
when (rhs) {
is Byte -> lhs + rhs
is Short -> lhs + rhs
is Int -> lhs + rhs
is Long -> lhs + rhs
is Float -> lhs + rhs
is Double -> lhs + rhs
else -> throw IncompatibleTypesException()
}
}
is Double -> {
when (rhs) {
is Byte -> lhs + rhs
is Short -> lhs + rhs
is Int -> lhs + rhs
is Long -> lhs + rhs
is Float -> lhs + rhs
is Double -> lhs + rhs
else -> throw IncompatibleTypesException()
}
}
is String -> lhs + rhs.toString()
else -> throw IncompatibleTypesException()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment