Skip to content

Instantly share code, notes, and snippets.

@bkase
Created April 23, 2016 09:03
Show Gist options
  • Save bkase/3d9c93fc01cedebeaf1b808f5414651a to your computer and use it in GitHub Desktop.
Save bkase/3d9c93fc01cedebeaf1b808f5414651a to your computer and use it in GitHub Desktop.
Playing with typeclasses in Scala
import simulacrum._
@typeclass trait CanTruthy[A] { self =>
@op("!!") def truthy(a: A): Boolean
}
object Main extends App {
import CanTruthy.ops._
implicit val truthyInt =
new CanTruthy[Int] {
def truthy(a: Int) = a != 0
}
implicit val truthyString =
new CanTruthy[String] {
def truthy(a: String) = a != ""
}
println(5 !!)
println("hello" !!)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment