trait Normalization[A] extends AnyRef
Defines a custom way to normalize instances of a type.
For example, to normalize Double
s by truncating off any decimal part,
you might write:
import org.scalactic._ val truncated = new Normalization[Double] { def normalized(d: Double) = d.floor }
Given this definition you could use it with the Explicitly
DSL like this:
import org.scalatest._ import Matchers._ import TypeCheckedTripleEquals._ (2.1 should === (2.0)) (after being truncated)
Note that to use a Normalization
with the Explicitly
DSL, you'll need to use
TypeCheckedTripleEquals
.
If you're just using plain-old
TripleEquals
, you'll need a Uniformity
, a Normalization
subclass.
If you make the truncated
val
implicit and import or mix in the members of NormMethods
,
you can access the behavior by invoking .norm
on Double
s.
implicit val doubleNormalization = truncated import NormMethods._ val d = 2.1 d.norm // returns 2.0
- A
the type whose normalization is being defined
- Self Type
- Normalization[A]
- Source
- Normalization.scala
- Alphabetic
- By Inheritance
- Normalization
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
normalized(a: A): A
Returns a normalized form of the passed object.
Returns a normalized form of the passed object.
If the passed object is already in normal form, this method may return the same instance passed.
- a
the object to normalize
- returns
the normalized form of the passed object
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
and(other: Normalization[A]): Normalization[A]
Returns a new
Normalization
that composes this and the passedNormalization
.Returns a new
Normalization
that composes this and the passedNormalization
.The
normalized
method of theNormalization
returned by this method returns a normalized form of the passed object obtained by forwarding the passed value first to thisNormalization
'snormalized
method, then passing that result to the otherNormalization
'snormalized
method. Essentially, the body of the composednormalized
method is:normalizationPassedToAnd.normalized(normalizationOnWhichAndWasInvoked.normalized(a))
- other
a
Normalization
to 'and' with this one- returns
a
Normalization
representing the composition of this and the passedNormalization
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
final
def
toEquivalence(implicit equivalence: Equivalence[A]): NormalizingEquivalence[A]
Converts this
Normalization
to aNormalizingEquivalence[A]
whosenormalized
method delegates to thisNormalization[A]
and whoseafterNormalizationEquivalence
field returns the implicitly passedEquivalence[A]
.Converts this
Normalization
to aNormalizingEquivalence[A]
whosenormalized
method delegates to thisNormalization[A]
and whoseafterNormalizationEquivalence
field returns the implicitly passedEquivalence[A]
.- equivalence
the
Equivalence
that the returnedNormalizingEquivalence
will delegate to determine equality after normalizing both left and right (if appropriate) sides.
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )