Helpers to write type-safe Scala code using equality and Strings.
(Usage below.)
"ai.x" %% "diff" % "1.2.0"
ScalaDependency( "ai.x", "diff", "1.2.0" )
import ai.x.safe._
Are ~
or ===
conflicting with other libraries you use?
For now do
import ai.x.safe.{ SafeEquals => _, SafeStringAdd => _, _ }
But open a ticket if anything is getting in your way or you have ideas how to improve things, etc.
Found any other type-safety holes in the Scala Standard Library and know a workaround? Why not submit a PR :)?
import ai.x.safe._
val guests = List( chris, ... )
chris == guests.find( _ == chris )
// false
val guests = List( chris, ... )
chris === guests.find( _ == chris )
// type error: Guest != Option[Guest]
val guests = List( chris, ... )
guests.contains( chrisId )
// false
val guests = List( chris, ... )
guests.safeContains( chrisId )
// error expected Guest, found GuestId
"Hi " + guest + ", ..."
// Hi Guest(1,Some(Chris)), ...
"Hi " ~ guestName ~ ", ..."
// error expected Guest, found Option[Guest]
"Hi " + names.mkString(" ") + ", ..."
// Hi Some(Chris) Some(Vogt), ...
"Hi " + names.safeMkString(" ") + ", ..."
// safeMkString is not a member of List[Option[String]]
s"Hi $guestName, ..."
// Hi Some(Chris), ...
safe"Hi $guestName, ..."
// expected String, found Option[String]