The companion object for NumericString that offers factory methods that produce NumericStrings.
Attributes
- Companion
- class
- Source
- NumericString.scala
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
NumericString.type
Members list
Value members
Concrete methods
A factory method, implemented via a macro, that produces a NumericString if passed a valid String literal, otherwise a compile time error.
A factory method, implemented via a macro, that produces a NumericString if passed a valid String 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 numeric String literal, i.e., it doesn't contain any non-digit characters (0-9), it will return a NumericString representing that value. Otherwise, the passed String 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 inspects String literals at compile time, whereas from inspects String values at run time.
Value parameters
- value
-
the
Stringliteral expression to inspect at compile time, and if it is a numeric string, to return wrapped in aNumericStringat run time.
Attributes
- Returns
-
the specified, valid
Stringliteral value wrapped in aNumericString. (If the specified expression is not a validStringliteral, the invocation of this method will not compile.) - Source
- NumericString.scala
A factory/assertion method that produces a NumericString given a valid String value, or throws AssertionError, if given an invalid String value.
A factory/assertion method that produces a NumericString given a valid String value, or throws AssertionError, if given an invalid String 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, or rightOrElse.
This method will inspect the passed String value and if it is a valid numeric string, it will return a NumericString representing that value. Otherwise, the passed String value is not a valid numeric string, so this method will throw AssertionError.
This factory method differs from the apply factory method in that apply is implemented via a macro that inspects String literals at compile time, whereas this method inspects String values at run time. It differs from a vanilla assert or ensuring call in that you get something you didn't already have if the assertion succeeds: a type that promises a String is numeric.
Value parameters
- value
-
the
Stringto inspect, and if numeric, return wrapped in aNumericString.
Attributes
- Returns
-
the specified
Stringvalue wrapped in aNumericString, if it is numeric, else throwsAssertionError. - Throws
-
AssertionError
if the passed value is not numeric
- Source
- NumericString.scala
A factory method that produces an Option[NumericString] given a String value.
A factory method that produces an Option[NumericString] given a String value.
This method will inspect the passed String value and if it is a numeric String, i.e., one that doesn't contain any non-digit characters, it will return a NumericString representing that value, wrapped in a Some. Otherwise, the passed String value is not a numeric string value, so this method will return None.
This factory method differs from the apply factory method in that apply is implemented via a macro that inspects String literals at compile time, whereas from inspects String values at run time.
Value parameters
- value
-
the
Stringto inspect, and if numeric, return wrapped in aSome[NumericString].
Attributes
- Returns
-
the specified
Stringvalue wrapped in aSome[NumericString], if it is numeric, elseNone. - Source
- NumericString.scala
A factory method that produces a NumericString given a String value and a default NumericString.
A factory method that produces a NumericString given a String value and a default NumericString.
This method will inspect the passed String value and if it is a valid numeric string, i.e., a String containing only numeric digit characters (0-9), it will return a NumericString representing that value. Otherwise, the passed String value contains non-digit characters, so this method will return the passed default value.
This factory method differs from the apply factory method in that apply is implemented via a macro that inspects String literals at compile time, whereas fromOrElse inspects String values at run time.
Value parameters
- default
-
the
NumericStringto return if the passedStringvalue is not numeric. - value
-
the
Stringto inspect, and if numeric, return.
Attributes
- Returns
-
the specified
Stringvalue wrapped in aNumericString, if it is numeric, else thedefaultNumericStringvalue. - Source
- NumericString.scala
A factory/validation method that produces a NumericString, wrapped in a Good, given a valid String value, or if the given String is invalid, an error value of type B produced by passing the given invalid String value to the given function f, wrapped in a Bad.
A factory/validation method that produces a NumericString, wrapped in a Good, given a valid String value, or if the given String is invalid, an error value of type B produced by passing the given invalid String value to the given function f, wrapped in a Bad.
This method will inspect the passed String value and if it is a numeric String, it will return a NumericString representing that value, wrapped in a Good. Otherwise, the passed String value is NOT numeric, so this method will return a result of type B obtained by passing the invalid String value to the given function f, wrapped in a Bad.
This factory method differs from the apply factory method in that apply is implemented via a macro that inspects String literals at compile time, whereas this method inspects String values at run time.
Value parameters
- value
-
the
Stringto inspect, and if numeric, return wrapped in aGood(NumericString).
Attributes
- Returns
-
the specified
Stringvalue wrapped in aGood(NumericString), if it is numeric, else aBad(f(value)). - Source
- NumericString.scala
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 parameters
- value
-
the
Stringto inspect, and if numeric, return true.
Attributes
- Returns
-
true if the specified
Stringis numeric, else false. - Source
- NumericString.scala
A validation method that produces a Pass given a valid String value, or an error value of type E produced by passing the given invalid String value to the given function f, wrapped in a Fail.
A validation method that produces a Pass given a valid String value, or an error value of type E produced by passing the given invalid String value to the given function f, wrapped in a Fail.
This method will inspect the passed String value and if it is a numeric String, it will return a Pass. Otherwise, the passed String value is non-numeric, so this method will return a result of type E obtained by passing the invalid String value to the given function f, wrapped in a Fail.
This factory method differs from the apply factory method in that apply is implemented via a macro that inspects String literals at compile time, whereas this method inspects String values at run time.
Value parameters
- value
-
the
Stringto validate that it is numeric.
Attributes
- Returns
-
a
Passif the specifiedStringvalue is numeric, else aFailcontaining an error value produced by passing the specifiedStringto the given functionf. - Source
- NumericString.scala
A factory/validation method that produces a NumericString, wrapped in a Right, given a valid String value, or if the given String is invalid, an error value of type L produced by passing the given invalid String value to the given function f, wrapped in a Left.
A factory/validation method that produces a NumericString, wrapped in a Right, given a valid String value, or if the given String is invalid, an error value of type L produced by passing the given invalid String value to the given function f, wrapped in a Left.
This method will inspect the passed String value and if it is a numeric String, it will return a NumericString representing that value, wrapped in a Right. Otherwise, the passed String value is NOT numeric, so this method will return a result of type L obtained by passing the invalid String value to the given function f, wrapped in a Left.
This factory method differs from the apply factory method in that apply is implemented via a macro that inspects String literals at compile time, whereas this method inspects String values at run time.
Value parameters
- value
-
the
Stringto inspect, and if numeric, return wrapped in aRight(NumericString).
Attributes
- Returns
-
the specified
Stringvalue wrapped in aRight(NumericString), if it is numeric, else aLeft(f(value)). - Source
- NumericString.scala
A factory/validation method that produces a NumericString, wrapped in a Success, given a valid String value, or if the given String is invalid, an AssertionError, wrapped in a Failure.
A factory/validation method that produces a NumericString, wrapped in a Success, given a valid String value, or if the given String is invalid, an AssertionError, wrapped in a Failure.
This method will inspect the passed String value and if it represents a numeric value, it will return a NumericString representing that value, wrapped in a Success. Otherwise, the passed String value is not numeric, so this method will return an AssertionError, wrapped in a Failure.
This factory method differs from the apply factory method in that apply is implemented via a macro that inspects String literals at compile time, whereas this method inspects String values at run time.
Value parameters
- value
-
the
Stringto inspect, and if numeric, return wrapped in aSuccess(NumericString).
Attributes
- Returns
-
the specified
Stringvalue wrapped in aSuccess(NumericString), if it is numeric, else aFailure(AssertionError). - Source
- NumericString.scala