Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

hseeberger/demo-equality

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

demo-equality

Demos for type-safe equality with Scala implicits.

The simplest approach gives you a type-safe yet unbalanced === equality operation:

scala> import name.heikoseeberger.demoequality._
import name.heikoseeberger.demoequality._

scala> import SimpleEquality._
import SimpleEquality._

scala> 123 === 666
res0: Boolean = false

scala> "a" === "a"
res1: Boolean = true

scala> 123 === "a"
<console>:14: error: type mismatch;
 found   : String("a")
 required: Int
              123 === "a"

scala> Seq(1, 2, 3) === List(1, 2, 3)
res3: Boolean = true

scala> List(1, 2, 3) === Seq(1, 2, 3)
<console>:17: error: type mismatch;
 found   : Seq[Int]
 required: List[Int]
              List(1, 2, 3) === Seq(1, 2, 3)

For type- or view-based balanced equality more information see my blog series "Implicits unchained – type-safe equality":

  • Part 1: simple yet unbalanced equality
  • Part 2: type-wise balanced equality
  • Part 3: view-wise balanced equality

Contribution policy

Contributions via GitHub pull requests are gladly accepted from their original author. Along with any pull requests, please state that the contribution is your original work and that you license the work to the project under the project's open source license. Whether or not you state this explicitly, by submitting any copyrighted material via pull request, email, or other means you agree to license the material under the project's open source license and warrant that you have the legal authority to do so.

License

This code is open source software licensed under the Apache 2.0 License.

About

Demos for type-safe equality with Scala implicits

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages