case classDomainName(labels: String*) extends Product with Serializable
A DomainName represents a name in the domain name system.
This class does not constrain the value of the domain name in anyway.
Unlike the example in Programming in Scala/2e the elements of the domain name are stored in the same order
as used, i.e. as www.scalacraft.com, not reversed.
This implementation is case sensitive which is at variance with the Wikipedia specification. If a convincing
use case for case insensitivity arises this could be reconsidered. Expressed in code we have,
DomainName("WWW") != DomainName("www")
Pattern Matching
Pattern matching is supported as the following example demonstrates,
A
DomainName
represents a name in the domain name system.This class does not constrain the value of the domain name in anyway.
Unlike the example in Programming in Scala/2e the elements of the domain name are stored in the same order as used, i.e. as
www.scalacraft.com
, not reversed.This implementation is case sensitive which is at variance with the Wikipedia specification. If a convincing use case for case insensitivity arises this could be reconsidered. Expressed in code we have,
Pattern Matching
Pattern matching is supported as the following example demonstrates,
Domain names with invalid labels will also be matched because this class is unconstrained,
To match an arbitrary number of domain name labels use a pattern sequence,
Implicit Conversions
Implicit conversions exist which allow an instance of
DomainName
to be used when either aString
orSeq[String]
is required.A conversion to an option of the constrained version of this class is also available.