Packages

t

s_mach.codetools

IsValueClass

trait IsValueClass[A] extends Any

A base trait for a user-defined value-class that standardizes the name of the value-class val to "underlying" and the toString implementation to underlying.toString. This allows creating an implicit conversion from an instance of any value-class to its underlying representation.

For details on value-class see: http://docs.scala-lang.org/overviews/core/value-classes.html

Example:

implicit class Name(underlying: String) extends AnyVal with IsValueType[String]

Note1: When creating a value-class for String, it is necessary to create an implicit view to StringOps to use the Scala extended String methods on instances of the value-class. Example:

object Name {
  import scala.collection.immutable.StringOps
  implicit def stringOps_Name(n: Name) = new StringOps(n.underlying)
}

Note2: while almost every method on underlying can be used on the value-class without special code, the equals method is a special case that still requires wrapping the right-hand type in the value-class to match the other side. Ex:

Name("Hal") == "Hal" // always returns false + compiler warning
Name("Hal") == Name("Hal") // works correctly
A

type of underlying value class (Note: this parameter does not require inheritance from AnyVal since this would prevent using the trait with java.lang.String which does not inherit AnyVal)

Linear Supertypes
Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. IsValueClass
  2. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def getClass(): Class[_]
    Definition Classes
    Any
  2. abstract def underlying: A

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    Any
  2. final def ##(): Int
    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def equals(arg0: Any): Boolean
    Definition Classes
    Any
  6. def hashCode(): Int
    Definition Classes
    Any
  7. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  8. def toString(): String
    Definition Classes
    IsValueClass → Any

Inherited from Any

Ungrouped