Skip to content

er1c/scala-typesafeequals

Repository files navigation

scala-typesafeequals

Build Maven Central

Macro based typesafe ===, =!=, isNull, isNotNull, nonNull

The macros provide a compile time check to ensure you never try to compare unrelated types. (e.g. 0 == ""). The macros generate the original (a == b) to avoid any extra boxing or allocations.

Similar .isNull, .isNotNull, and .nonNull helpers are provided to avoid using foo == null.

Documentation

Links:

Usage

Add this to your build.sbt:

libraryDependencies += "io.github.er1c" %% "scala-typesafeequals" % "1.0.0" % Compile

For Scala.js

libraryDependencies += "io.github.er1c" %%% "scala-typesafeequals" % "1.0.0" % Compile

Cross-builds are available for Scala 2.11.12, 2.12.11 and 2.13.3.

Find out more in the microsite.

Implicits

Implicits.scala is provided to extend in your own implicits object.

To import all implicits:

import typesafeequals._

For selective imports:

import typesafeequals.TypeSafeEquals._
import typesafeequals.AnyRefNullChecks._

TypeSafeEquals

import typesafeequals._

val a = "foo"
val b = "bar"
val i = 0

a === a // true
a === b // false
a =!= b // true
a =!= a // false
a === i // won't compile
a =!= i // won't compile

AnyRefNullChecks

import typesafeequals._

val a = "foo"
val b = null

a.isNull // false
b.isNull // true

a.isNotNull // true
b.isNotNull // false

a.nonNull // true
b.nonNull // false

Contributing

The Type Safe Equals project welcomes contributions from anybody wishing to participate. All code or documentation that is provided must be licensed with the same license that Type Safe Equals is licensed with (Apache 2.0, see LICENCE).

People are expected to follow the Scala Code of Conduct when discussing Type Safe Equals on GitHub, Gitter channel, or other venues.

Feel free to open an issue if you notice a bug, have an idea for a feature, or have a question about the code. Pull requests are also gladly accepted. For more information, check out the contributor guide.

License

All code in this repository is licensed under the Apache License, Version 2.0. See LICENCE.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published