trait
SetEqualityConstraints extends AnyRef
Value Members
-
final
def
!=(arg0: AnyRef): Boolean
-
final
def
!=(arg0: Any): Boolean
-
final
def
##(): Int
-
final
def
==(arg0: AnyRef): Boolean
-
final
def
==(arg0: Any): Boolean
-
final
def
asInstanceOf[T0]: T0
-
def
clone(): AnyRef
-
final
def
eq(arg0: AnyRef): Boolean
-
def
equals(arg0: Any): Boolean
-
def
finalize(): Unit
-
final
def
getClass(): Class[_]
-
def
hashCode(): Int
-
final
def
isInstanceOf[T0]: Boolean
-
final
def
ne(arg0: AnyRef): Boolean
-
final
def
notify(): Unit
-
final
def
notifyAll(): Unit
-
implicit
def
setEqualityConstraint[EA, CA[ea] <: GenSet[ea], EB, CB[eb] <: GenSet[eb]](implicit equalityOfA: Equality[CA[EA]], ev: Constraint[EA, EB]): Constraint[CA[EA], CB[EB]]
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
-
def
toString(): String
-
final
def
wait(): Unit
-
final
def
wait(arg0: Long, arg1: Int): Unit
-
final
def
wait(arg0: Long): Unit
Inherited from AnyRef
Inherited from Any
Provides an implicit method that loosens the equality constraint defined by
TypeCheckedTripleEqualsorConversionCheckedTripleEqualsfor ScalaSets to one that more closely matches Scala's approach toSetequality.Scala's approach to
Setequality is that if both objects being compared areSets, the elements are compared to determine equality. This means you could compare an immutableTreeSetand a mutableHashSetfor equality, for instance, and get true so long as the twoSets contained the same elements in the same order. Here's an example:Such a comparison would not, however, compile if you used
===under eitherTypeCheckedTripleEqualsorConversionCheckedTripleEquals, becauseTreeSetandHashSetare not in a subtype/supertype relationship, nor does an implicit conversion by default exist between them:scala> import org.scalautils._ import org.scalautils._ scala> import TypeCheckedTripleEquals._ import TypeCheckedTripleEquals._ scala> TreeSet(1, 2) === HashSet(1, 2) <console>:16: error: types scala.collection.immutable.TreeSet[Int] and scala.collection.mutable.HashSet[Int] do not adhere to the equality constraint selected for the === and !== operators; the missing implicit parameter is of type org.scalautils.EqualityConstraint[scala.collection.immutable.TreeSet[Int], scala.collection.mutable.HashSet[Int]] TreeSet(1, 2) === HashSet(1, 2) ^If you mix or import the implicit conversion provided by
SetEqualityConstraint, however, the comparison will be allowed:The equality constraint provided by this trait requires that both left and right sides are subclasses of
scala.collection.GenSetand that anEqualityConstraintcan be found for the element types. In the example above, both theTreeSetandHashSetare subclasses ofscala.collection.GenSet, and the regularTypeCheckedTripleEqualsprovides equality constraints for the element types, both of which areInt. By contrast, this trait would not allow aTreeSet[Int]to be compared against aHashSet[java.util.Date], because no equality constraint will exist between the element typesIntandDate:scala> import java.util.Date import java.util.Date scala> TreeSet(1, 2) === HashSet(new Date, new Date) <console>:20: error: types scala.collection.immutable.TreeSet[Int] and scala.collection.mutable.HashSet[java.util.Date] do not adhere to the equality constraint selected for the === and !== operators; the missing implicit parameter is of type org.scalautils.EqualityConstraint[scala.collection.immutable.TreeSet[Int], scala.collection.mutable.HashSet[java.util.Date]] TreeSet(1, 2) === HashSet(new Date, new Date) ^