The companion object for NonZeroInt
that offers factory methods that
produce NonZeroInt
s, implicit widening conversions from NonZeroInt
to other numeric types, and maximum and minimum constant values for NonZeroInt
.
- Companion:
- class
- Source:
- NonZeroInt.scala
Value members
Concrete methods
A factory/assertion method that produces a NonZeroInt
given a
valid Int
value, or throws AssertionError
,
if given an invalid Int
value.
A factory/assertion method that produces a NonZeroInt
given a
valid Int
value, or throws AssertionError
,
if given an invalid Int
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 Int
value and if
it is a non-zero Int
, it will return a NonZeroInt
representing that value. Otherwise, the passed Int
value is not non-zero, 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
Int
literals at compile time, whereas this method inspects
Int
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 an Int
is non-zero.
- Value parameters:
- value
the
Int
to inspect, and if non-zero, return wrapped in aNonZeroInt
.
- Returns:
the specified
Int
value wrapped in aNonZeroInt
, if it is non-zero, else throwsAssertionError
.- Throws:
- AssertionError
if the passed value is not non-zero
- Source:
- NonZeroInt.scala
A factory method that produces an Option[NonZeroInt]
given an
Int
value.
A factory method that produces an Option[NonZeroInt]
given an
Int
value.
This method will inspect the passed Int
value and if
it is a non-zero Int
, i.e., a non-zero integer value,
it will return a NonZeroInt
representing that value,
wrapped in a Some
. Otherwise, the passed Int
value is not non-zero integer 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
Int
literals at compile time, whereas from
inspects
Int
values at run time.
- Value parameters:
- value
the
Int
to inspect, and if non-zero, return wrapped in aSome[NonZeroInt]
.
- Returns:
the specified
Int
value wrapped in aSome[NonZeroInt]
, if it is non-zero, elseNone
.- Source:
- NonZeroInt.scala
A factory method that produces a NonZeroInt
given a
Int
value and a default NonZeroInt
.
A factory method that produces a NonZeroInt
given a
Int
value and a default NonZeroInt
.
This method will inspect the passed Int
value and if
it is a positive Int
, i.e., a value greater
than 0.0, it will return a NonZeroInt
representing that value.
Otherwise, the passed Int
value is 0 or negative, 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 Int
literals at
compile time, whereas from
inspects
Int
values at run time.
- Value parameters:
- default
the
NonZeroInt
to return if the passedInt
value is not positive.- value
the
Int
to inspect, and if positive, return.
- Returns:
the specified
Int
value wrapped in aNonZeroInt
, if it is positive, else thedefault
NonZeroInt
value.- Source:
- NonZeroInt.scala
A factory/validation method that produces a NonZeroInt
, wrapped
in a Good
, given a valid Int
value, or if the
given Int
is invalid, an error value of type B
produced by passing the given invalid Int
value
to the given function f
, wrapped in a Bad
.
A factory/validation method that produces a NonZeroInt
, wrapped
in a Good
, given a valid Int
value, or if the
given Int
is invalid, an error value of type B
produced by passing the given invalid Int
value
to the given function f
, wrapped in a Bad
.
This method will inspect the passed Int
value and if
it is a non-zero Int
, it will return a NonZeroInt
representing that value, wrapped in a Good
.
Otherwise, the passed Int
value is not non-zero, so this
method will return a result of type B
obtained by passing
the invalid Int
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
Int
literals at compile time, whereas this method inspects
Int
values at run time.
- Value parameters:
- value
the
Int
to inspect, and if non-zero, return wrapped in aGood(NonZeroInt)
.
- Returns:
the specified
Int
value wrapped in aGood(NonZeroInt)
, if it is non-zero, else aBad(f(value))
.- Source:
- NonZeroInt.scala
A predicate method that returns true if a given
Int
value is non-zero.
A predicate method that returns true if a given
Int
value is non-zero.
- Value parameters:
- value
the
Int
to inspect, and if non-zero, return true.
- Returns:
true if the specified
Int
is non-zero, else false.- Source:
- NonZeroInt.scala
A validation method that produces a Pass
given a valid Int
value, or
an error value of type E
produced by passing the
given invalid Int
value
to the given function f
, wrapped in a Fail
.
A validation method that produces a Pass
given a valid Int
value, or
an error value of type E
produced by passing the
given invalid Int
value
to the given function f
, wrapped in a Fail
.
This method will inspect the passed Int
value and if
it is a non-zero Int
, it will return a Pass
.
Otherwise, the passed Int
value is non-zero, so this
method will return a result of type E
obtained by passing
the invalid Int
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
Int
literals at compile time, whereas this method inspects
Int
values at run time.
- Value parameters:
- value
the
Int
to validate that it is non-zero.
- Returns:
a
Pass
if the specifiedInt
value is non-zero, else aFail
containing an error value produced by passing the specifiedInt
to the given functionf
.- Source:
- NonZeroInt.scala
A factory/validation method that produces a NonZeroInt
, wrapped
in a Right
, given a valid Int
value, or if the
given Int
is invalid, an error value of type L
produced by passing the given invalid Int
value
to the given function f
, wrapped in a Left
.
A factory/validation method that produces a NonZeroInt
, wrapped
in a Right
, given a valid Int
value, or if the
given Int
is invalid, an error value of type L
produced by passing the given invalid Int
value
to the given function f
, wrapped in a Left
.
This method will inspect the passed Int
value and if
it is a non-zero Int
, it will return a NonZeroInt
representing that value, wrapped in a Right
.
Otherwise, the passed Int
value is not non-zero, so this
method will return a result of type L
obtained by passing
the invalid Int
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
Int
literals at compile time, whereas this method inspects
Int
values at run time.
- Value parameters:
- value
the
Int
to inspect, and if non-zero, return wrapped in aRight(NonZeroInt)
.
- Returns:
the specified
Int
value wrapped in aRight(NonZeroInt)
, if it is non-zero, else aLeft(f(value))
.- Source:
- NonZeroInt.scala
A factory/validation method that produces a NonZeroInt
, wrapped
in a Success
, given a valid Int
value, or if the
given Int
is invalid, an AssertionError
, wrapped
in a Failure
.
A factory/validation method that produces a NonZeroInt
, wrapped
in a Success
, given a valid Int
value, or if the
given Int
is invalid, an AssertionError
, wrapped
in a Failure
.
This method will inspect the passed Int
value and if
it is a non-zero Int
, it will return a NonZeroInt
representing that value, wrapped in a Success
.
Otherwise, the passed Int
value is not non-zero, 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
Int
literals at compile time, whereas this method inspects
Int
values at run time.
- Value parameters:
- value
the
Int
to inspect, and if non-zero, return wrapped in aSuccess(NonZeroInt)
.
- Returns:
the specified
Int
value wrapped in aSuccess(NonZeroInt)
, if it is non-zero, else aFailure(AssertionError)
.- Source:
- NonZeroInt.scala
Concrete fields
The largest value representable as a non-zero Int
, which is NonZeroInt(2147483647)
.
The largest value representable as a non-zero Int
, which is NonZeroInt(2147483647)
.
- Source:
- NonZeroInt.scala
The smallest value representable as a non-zero Int
, which is NonZeroInt(-2147483648)
.
The smallest value representable as a non-zero Int
, which is NonZeroInt(-2147483648)
.
- Source:
- NonZeroInt.scala
Implicits
Implicits
A factory method, implemented via a macro, that produces a NonZeroInt
if passed a valid Int
literal, otherwise a compile time error.
A factory method, implemented via a macro, that produces a NonZeroInt
if passed a valid Int
literal, otherwise a compile time error.
The macro that implements this method will inspect the specified Int
expression at compile time. If
the expression is a positive Int
literal, i.e., with a
value greater than 0, it will return a NonZeroInt
representing that value.
Otherwise, the passed Int
expression is either a literal that is 0 or negative, 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
Int
literals at compile time, whereas from
inspects
Int
values at run time.
- Value parameters:
- value
the
Int
literal expression to inspect at compile time, and if positive, to return wrapped in aNonZeroInt
at run time.
- Returns:
the specified, valid
Int
literal value wrapped in aNonZeroInt
. (If the specified expression is not a validInt
literal, the invocation of this method will not compile.)- Source:
- NonZeroInt.scala
Implicit widening conversion from NonZeroInt
to Double
.
Implicit widening conversion from NonZeroInt
to Double
.
- Value parameters:
- pos
the
NonZeroInt
to widen
- Returns:
the
Int
value underlying the specifiedNonZeroInt
, widened toDouble
.- Source:
- NonZeroInt.scala
Implicit widening conversion from NonZeroInt
to Float
.
Implicit widening conversion from NonZeroInt
to Float
.
- Value parameters:
- pos
the
NonZeroInt
to widen
- Returns:
the
Int
value underlying the specifiedNonZeroInt
, widened toFloat
.- Source:
- NonZeroInt.scala
Implicit widening conversion from NonZeroInt
to Int
.
Implicit widening conversion from NonZeroInt
to Int
.
- Value parameters:
- pos
the
NonZeroInt
to widen
- Returns:
the
Int
value underlying the specifiedNonZeroInt
.- Source:
- NonZeroInt.scala
Implicit widening conversion from NonZeroInt
to Long
.
Implicit widening conversion from NonZeroInt
to Long
.
- Value parameters:
- pos
the
NonZeroInt
to widen
- Returns:
the
Int
value underlying the specifiedNonZeroInt
, widened toLong
.- Source:
- NonZeroInt.scala
Implicit widening conversion from NonZeroInt
to NonZeroDouble
.
Implicit widening conversion from NonZeroInt
to NonZeroDouble
.
- Value parameters:
- pos
the
NonZeroInt
to widen
- Returns:
the
Int
value underlying the specifiedNonZeroInt
, widened toDouble
and wrapped in aNonZeroDouble
.- Source:
- NonZeroInt.scala
Implicit widening conversion from NonZeroInt
to NonZeroFloat
.
Implicit widening conversion from NonZeroInt
to NonZeroFloat
.
- Value parameters:
- pos
the
NonZeroInt
to widen
- Returns:
the
Int
value underlying the specifiedNonZeroInt
, widened toFloat
and wrapped in aNonZeroFloat
.- Source:
- NonZeroInt.scala
Implicit widening conversion from NonZeroInt
to NonZeroLong
.
Implicit widening conversion from NonZeroInt
to NonZeroLong
.
- Value parameters:
- pos
the
NonZeroInt
to widen
- Returns:
the
Int
value underlying the specifiedNonZeroInt
, widened toLong
and wrapped in aNonZeroLong
.- Source:
- NonZeroInt.scala