org.scalautils

SeqEqualityConstraints

trait SeqEqualityConstraints extends AnyRef

Provides an implicit method that loosens the equality constraint defined by TypeCheckedTripleEquals or ConversionCheckedTripleEquals for Scala Seqs to one that more closely matches Scala's approach to Seq equality.

Scala's approach to Seq equality is that if both objects being compared are Seqs, the elements are compared to determine equality. This means you could compare an immutable Vector and a mutable ListBuffer for equality, for instance, and get true so long as the two Seqs contained the same elements in the same order. Here's an example:

scala> import scala.collection.mutable.ListBuffer
import scala.collection.mutable.ListBuffer

scala> Vector(1, 2) == ListBuffer(1, 2) res0: Boolean = true

Such a comparison would not, however, compile if you used === under either TypeCheckedTripleEquals or ConversionCheckedTripleEquals, because Vector and ListBuffer are 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> Vector(1, 2) === ListBuffer(1, 2) <console>:16: error: types scala.collection.immutable.Vector[Int] and scala.collection.mutable.ListBuffer[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.Vector[Int], scala.collection.mutable.ListBuffer[Int]] Vector(1, 2) === ListBuffer(1, 2) ^

If you mix or import the implicit conversion provided by SeqEqualityConstraint, however, the comparison will be allowed:

scala> import SeqEqualityConstraints._
import SeqEqualityConstraints._

scala> Vector(1, 2) === ListBuffer(1, 2) res2: Boolean = true

The equality constraint provided by this trait requires that both left and right sides are subclasses of scala.collection.GenSeq and that an EqualityConstraint can be found for the element types. In the example above, both the Vector and ListBuffer are subclasses of scala.collection.GenSeq, and the regular TypeCheckedTripleEquals provides equality constraints for the element types, both of which are Int. By contrast, this trait would not allow a Vector[Int] to be compared against a ListBuffer[java.util.Date], because no equality constraint will exist between the element types Int and Date:

scala> import java.util.Date
import java.util.Date

scala> Vector(1, 2) === ListBuffer(new Date, new Date) <console>:20: error: types scala.collection.immutable.Vector[Int] and scala.collection.mutable.ListBuffer[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.Vector[Int], scala.collection.mutable.ListBuffer[java.util.Date]] Vector(1, 2) === ListBuffer(new Date, new Date) ^

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. SeqEqualityConstraints
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  8. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  11. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  17. implicit def seqEqualityConstraint[EA, CA[ea] <: GenSeq[ea], EB, CB[eb] <: GenSeq[eb]](implicit equalityOfA: Equality[CA[EA]], ev: Constraint[EA, EB]): Constraint[CA[EA], CB[EB]]

    Provides an equality constraint that allows two subtypes of scala.collection.GenSeqs to be compared for equality with === so long as an EqualityConstraint is available for the element types.

  18. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  19. def toString(): String

    Definition Classes
    AnyRef → Any
  20. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  21. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  22. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from AnyRef

Inherited from Any

Ungrouped