Skip to content

Instantly share code, notes, and snippets.

@ukitaka
Created June 14, 2017 09:59
Show Gist options
  • Save ukitaka/c43982224880794598e5d86fe4fda64f to your computer and use it in GitHub Desktop.
Save ukitaka/c43982224880794598e5d86fe4fda64f to your computer and use it in GitHub Desktop.
trait From[T, S] {
def from(t: T): S
}
object From {
def from[T, S](t: T)(implicit F: From[T, S]): S = F.from(t)
}
implicit val fromIntToString = new From[Int, String] {
def from(i: Int): String = i.toString
}
implicit val fromDoubleToString = new From[Double, String] {
def from(d: Double): String = d.toString
}
implicit val fromBooleanToString = new From[Boolean, String] {
def from(b: Boolean): String = b.toString
}
val str1: String = From.from(1)
val str2: String = From.from(true)
val str3: String = From.from(4.2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment