Eq

December 11, 2012

trait Eq[A] {
  def eq(x: A, y: A): Boolean
}

object Eq {
  implicit def anyEquals[A]: Eq[A] =
    new Eq[A] {
      def eq(x: A, y: A): Boolean =
        x == y
    }
  implicit class EqOps[A: Eq](x: A) {
    def ===(y: A): Boolean =
      implicitly[Eq[A]].eq(x, y)
  }
}

Dependencies

Example

import Eq._

println((6 * 7) === 42) // true

// println((6 * 7) === "42") // won't compile