object NumericString
The companion object for NumericString
that offers factory
methods that produce NumericString
s.
- Source
- NumericString.scala
- Alphabetic
- By Inheritance
- NumericString
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
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
- macro def apply(value: String): NumericString
A factory method, implemented via a macro, that produces a
NumericString
if passed a validString
literal, otherwise a compile time error.A factory method, implemented via a macro, that produces a
NumericString
if passed a validString
literal, otherwise a compile time error.The macro that implements this method will inspect the specified
String
expression at compile time. If the expression is a numericString
literal, i.e., it doesn't contain any non-digit characters (0-9), it will return aNumericString
representing that value. Otherwise, the passedString
expression is either a literal that contains non-digit characters, or is not a literal, so this method will give a compiler error.This factory method differs from the
from
factory method in that this method is implemented via a macro that inspectsString
literals at compile time, whereasfrom
inspectsString
values at run time.- value
the
String
literal expression to inspect at compile time, and if it is a numeric string, to return wrapped in aNumericString
at run time.- returns
the specified, valid
String
literal value wrapped in aNumericString
. (If the specified expression is not a validString
literal, the invocation of this method will not compile.)
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def ensuringValid(value: String): NumericString
A factory/assertion method that produces a
NumericString
given a validString
value, or throwsAssertionError
, if given an invalidString
value.A factory/assertion method that produces a
NumericString
given a validString
value, or throwsAssertionError
, if given an invalidString
value.Note: you should use this method only when you are convinced that it will always succeed, i.e., never throw an exception. It is good practice to add a comment near the invocation of this method indicating why you think it will always succeed to document your reasoning. If you are not sure an
ensuringValid
call will always succeed, you should use one of the other factory or validation methods provided on this object instead:isValid
,tryingValid
,passOrElse
,goodOrElse
, orrightOrElse
.This method will inspect the passed
String
value and if it is a valid numeric string, it will return aNumericString
representing that value. Otherwise, the passedString
value is not a valid numeric string, so this method will throwAssertionError
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsString
literals at compile time, whereas this method inspectsString
values at run time. It differs from a vanillaassert
orensuring
call in that you get something you didn't already have if the assertion succeeds: a type that promises aString
is numeric.- value
the
String
to inspect, and if numeric, return wrapped in aNumericString
.- returns
the specified
String
value wrapped in aNumericString
, if it is numeric, else throwsAssertionError
.
- Exceptions thrown
AssertionError
if the passed value is not numeric
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def from(value: String): Option[NumericString]
A factory method that produces an
Option[NumericString]
given aString
value.A factory method that produces an
Option[NumericString]
given aString
value.This method will inspect the passed
String
value and if it is a numericString
, i.e., one that doesn't contain any non-digit characters, it will return aNumericString
representing that value, wrapped in aSome
. Otherwise, the passedString
value is not a numeric string value, so this method will returnNone
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsString
literals at compile time, whereasfrom
inspectsString
values at run time.- value
the
String
to inspect, and if numeric, return wrapped in aSome[NumericString]
.- returns
the specified
String
value wrapped in aSome[NumericString]
, if it is numeric, elseNone
.
- def fromOrElse(value: String, default: => NumericString): NumericString
A factory method that produces a
NumericString
given aString
value and a defaultNumericString
.A factory method that produces a
NumericString
given aString
value and a defaultNumericString
.This method will inspect the passed
String
value and if it is a valid numeric string, i.e., aString
containing only numeric digit characters (0-9), it will return aNumericString
representing that value. Otherwise, the passedString
value contains non-digit characters, so this method will return the passeddefault
value.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsString
literals at compile time, whereasfromOrElse
inspectsString
values at run time.- value
the
String
to inspect, and if numeric, return.- default
the
NumericString
to return if the passedString
value is not numeric.- returns
the specified
String
value wrapped in aNumericString
, if it is numeric, else thedefault
NumericString
value.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def goodOrElse[B](value: String)(f: (String) => B): Or[NumericString, B]
A factory/validation method that produces a
NumericString
, wrapped in aGood
, given a validString
value, or if the givenString
is invalid, an error value of typeB
produced by passing the given invalidString
value to the given functionf
, wrapped in aBad
.A factory/validation method that produces a
NumericString
, wrapped in aGood
, given a validString
value, or if the givenString
is invalid, an error value of typeB
produced by passing the given invalidString
value to the given functionf
, wrapped in aBad
.This method will inspect the passed
String
value and if it is a numericString
, it will return aNumericString
representing that value, wrapped in aGood
. Otherwise, the passedString
value is NOT numeric, so this method will return a result of typeB
obtained by passing the invalidString
value to the given functionf
, wrapped in aBad
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsString
literals at compile time, whereas this method inspectsString
values at run time.- value
the
String
to inspect, and if numeric, return wrapped in aGood(NumericString)
.- returns
the specified
String
value wrapped in aGood(NumericString)
, if it is numeric, else aBad(f(value))
.
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isValid(value: String): Boolean
A predicate method that returns true if a given
String
value contains only numeric digit characters (0-9).A predicate method that returns true if a given
String
value contains only numeric digit characters (0-9).- value
the
String
to inspect, and if numeric, return true.- returns
true if the specified
String
is numeric, else false.
- 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()
- def passOrElse[E](value: String)(f: (String) => E): Validation[E]
A validation method that produces a
Pass
given a validString
value, or an error value of typeE
produced by passing the given invalidString
value to the given functionf
, wrapped in aFail
.A validation method that produces a
Pass
given a validString
value, or an error value of typeE
produced by passing the given invalidString
value to the given functionf
, wrapped in aFail
.This method will inspect the passed
String
value and if it is a numericString
, it will return aPass
. Otherwise, the passedString
value is non-numeric, so this method will return a result of typeE
obtained by passing the invalidString
value to the given functionf
, wrapped in aFail
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsString
literals at compile time, whereas this method inspectsString
values at run time.- value
the
String
to validate that it is numeric.- returns
a
Pass
if the specifiedString
value is numeric, else aFail
containing an error value produced by passing the specifiedString
to the given functionf
.
- def rightOrElse[L](value: String)(f: (String) => L): Either[L, NumericString]
A factory/validation method that produces a
NumericString
, wrapped in aRight
, given a validString
value, or if the givenString
is invalid, an error value of typeL
produced by passing the given invalidString
value to the given functionf
, wrapped in aLeft
.A factory/validation method that produces a
NumericString
, wrapped in aRight
, given a validString
value, or if the givenString
is invalid, an error value of typeL
produced by passing the given invalidString
value to the given functionf
, wrapped in aLeft
.This method will inspect the passed
String
value and if it is a numericString
, it will return aNumericString
representing that value, wrapped in aRight
. Otherwise, the passedString
value is NOT numeric, so this method will return a result of typeL
obtained by passing the invalidString
value to the given functionf
, wrapped in aLeft
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsString
literals at compile time, whereas this method inspectsString
values at run time.- value
the
String
to inspect, and if numeric, return wrapped in aRight(NumericString)
.- returns
the specified
String
value wrapped in aRight(NumericString)
, if it is numeric, else aLeft(f(value))
.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def tryingValid(value: String): Try[NumericString]
A factory/validation method that produces a
NumericString
, wrapped in aSuccess
, given a validString
value, or if the givenString
is invalid, anAssertionError
, wrapped in aFailure
.A factory/validation method that produces a
NumericString
, wrapped in aSuccess
, given a validString
value, or if the givenString
is invalid, anAssertionError
, wrapped in aFailure
.This method will inspect the passed
String
value and if it represents a numeric value, it will return aNumericString
representing that value, wrapped in aSuccess
. Otherwise, the passedString
value is not numeric, so this method will return anAssertionError
, wrapped in aFailure
.This factory method differs from the
apply
factory method in thatapply
is implemented via a macro that inspectsString
literals at compile time, whereas this method inspectsString
values at run time.- value
the
String
to inspect, and if numeric, return wrapped in aSuccess(NumericString)
.- returns
the specified
String
value wrapped in aSuccess(NumericString)
, if it is numeric, else aFailure(AssertionError)
.
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()