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.
the String
literal expression to inspect at
compile time, and if it is a numeric string, to return wrapped in a
NumericString
at run time.
the specified, valid String
literal value wrapped
in a NumericString
. (If the specified expression is not
a valid String
literal, the invocation of this method
will not compile.)
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.
the String
to inspect, and if numeric, return
wrapped in a NumericString
.
the specified String
value wrapped in a
NumericString
, if it is numeric, else throws
AssertionError
.
AssertionError
if the passed value is not numeric
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.
the String
to inspect, and if numeric, return
wrapped in a Some[NumericString]
.
the specified String
value wrapped
in a Some[NumericString]
, if it is numeric, else
None
.
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.
the String
to inspect, and if numeric, return.
the NumericString
to return if the passed
String
value is not numeric.
the specified String
value wrapped in a
NumericString
, if it is numeric, else the
default
NumericString
value.
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.
the String
to inspect, and if numeric, return
wrapped in a Good(NumericString)
.
the specified String
value wrapped
in a Good(NumericString)
, if it is numeric, else a
Bad(f(value))
.
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).
the String
to inspect, and if numeric, return
true.
true if the specified String
is numeric, else false.
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.
the String
to validate that it is numeric.
a Pass
if the specified String
value is numeric,
else a Fail
containing an error value produced by passing the
specified String
to the given function f
.
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.
the String
to inspect, and if numeric, return
wrapped in a Right(NumericString)
.
the specified String
value wrapped
in a Right(NumericString)
, if it is numeric, else a
Left(f(value))
.
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.
the String
to inspect, and if numeric, return
wrapped in a Success(NumericString)
.
the specified String
value wrapped
in a Success(NumericString)
, if it is numeric, else a
Failure(AssertionError)
.
The companion object for
NumericString
that offers factory methods that produceNumericString
s.