package anyvals
- Alphabetic
- Public
- Protected
Type Members
-    trait CompileTimeAssertions extends AnyRefTrait providing assertion methods that can be called at compile time from macros to validate literals in source code. Trait providing assertion methods that can be called at compile time from macros to validate literals in source code. The intent of CompileTimeAssertionsis to make it easier to createAnyVals that restrict the values of types for which Scala supports literals:Int,Long,Float,Double,Char, andString. For example, if you are using odd integers in many places in your code, you might have validity checks scattered throughout your code. Here's an example of a method that both requires an oddIntis passed (as a precondition, and ensures an odd *Intis returned (as a postcondition):def nextOdd(i: Int): Int = { def isOdd(x: Int): Boolean = x.abs % 2 == 1 require(isOdd(i)) (i + 2) ensuring (isOdd(_)) } In either the precondition or postcondition check fails, an exception will be thrown at runtime. If you have many methods like this you may want to create a type to represent an odd Int, so that the checking for validity errors is isolated in just one place. By using anAnyValyou can avoid boxing theInt, which may be more efficient. This might look like:final class OddInt private (val value: Int) extends AnyVal { override def toString: String = s"OddInt($value)" } 
 object OddInt { def apply(value: Int): OddInt = { require(value.abs % 2 == 1) new OddInt(value) } }An AnyValcannot have any constructor code, so to ensure that anyIntpassed to theOddIntconstructor is actually odd, the constructor must be private. That way the only way to construct a newOddIntis via theapplyfactory method in theOddIntcompanion object, which can require that the value be odd. This design eliminates the need for placingrequireandensuringclauses anywhere else that oddInts are needed, because the type promises the constraint. ThenextOddmethod could, therefore, be rewritten as:def nextOdd(oi: OddInt): OddInt = OddInt(oi.value + 2) Using the compile-time assertions provided by this trait, you can construct a factory method implemented via a macro that causes a compile failure if OddInt.applyis passed anything besides an oddIntliteral. ClassOddIntwould look exactly the same as before:final class OddInt private (val value: Int) extends AnyVal { override def toString: String = s"OddInt($value)" } In the companion object, however, the applymethod would be implemented in terms of a macro. Because theapplymethod will only work with literals, you'll need a second method that can work an any expression of typeInt. We recommend afrommethod that returns anOption[OddInt]that returnsSome[OddInt}if the passedIntis odd, else returnsNone, and anensuringValidmethod that returns anOddIntif the passedIntis valid, else throwsAssertionError.object OddInt { 
 // The from factory method validates at run time def from(value: Int): Option[OddInt] = if (OddIntMacro.isValid(value)) Some(new OddInt(value)) else None
 // The ensuringValid factory method validates at run time, but throws // an AssertionError if invalid def ensuringValid(value: Int): OddInt = if (OddIntMacro.isValid(value)) new OddInt(value) else { throw new AssertionError(s"$value was not a valid OddInt") }
 // The apply factory method validates at compile time import scala.language.experimental.macros def apply(value: Int): OddInt = macro OddIntMacro.apply }The applymethod refers to a macro implementation method in classPosIntMacro. The macro implementation of any such method can look very similar to this one. The only changes you'd need to make is theisValidmethod implementation and the text of the error messages.import org.scalactic.anyvals.CompileTimeAssertions import reflect.macros.Context 
 object OddIntMacro extends CompileTimeAssertions {
 // Validation method used at both compile- and run-time def isValid(i: Int): Boolean = i.abs % 2 == 1
 // Apply macro that performs a compile-time assertion def apply(c: Context)(value: c.Expr[Int]): c.Expr[OddInt] = {
 // Prepare potential compiler error messages val notValidMsg = "OddInt.apply can only be invoked on odd Int literals, like OddInt(3)." val notLiteralMsg = "OddInt.apply can only be invoked on Int literals, like " + "OddInt(3). Please use OddInt.from instead."
 // Validate via a compile-time assertion ensureValidIntLiteral(c)(value, notValidMsg, notLiteralMsg)(isValid)
 // Validated, so rewrite the apply call to a from call c.universe.reify { OddInt.ensuringValid(value.splice) } } }The isValidmethod just takes the underlying type and returnstrueif it is valid, elsefalse. This method is placed here so the same valiation code can be used both in thefrommethod at runtime and theapplymacro at compile time. Theapplyactually does just two things. It calls aensureValidIntLiteral, performing a compile-time assertion that value passed toapplyis anIntliteral that is valid (in this case, odd). If the assertion fails,ensureValidIntLiteralwill complete abruptly with an exception that will contain an appropriate error message (one of the two you passed in) and cause a compiler error with that message. If the assertion succeeds,ensureValidIntLiteralwill just return normally. The next line of code will then execute. This line of code must construct an AST (abstract syntax tree) of code that will replace theOddInt.applyinvocation. We invoke the other factory method that either returns anOddIntor throws anAssertionError, since we've proven at compile time that the call will succeed.You may wish to use quasi-quotes instead of reify. The reason we use reify is that this also works on 2.10 without any additional plugin (i.e., you don't need macro paradise), and Scalactic supports 2.10. 
-   final  class FiniteDouble extends AnyValAn AnyValfor finiteDoubles.An AnyValfor finiteDoubles.Because FiniteDoubleis anAnyValit will usually be as efficient as anDouble, being boxed only when aDoublewould have been boxed.The FiniteDouble.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingFiniteDouble.applywith a literalDoublevalue will either produce a validFiniteDoubleinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> FiniteDouble(1.1) res1: org.scalactic.anyvals.FiniteDouble = FiniteDouble(1.1) scala> FiniteDouble(Finite.PositiveInfinity) <console>:14: error: FiniteDouble.apply can only be invoked on a finite (i != Double.NegativeInfinity && i != Double.PositiveInfinity && !i.isNaN) floating point literal, like FiniteDouble(1.1). FiniteDouble(Finite.PositiveInfinity) ^FiniteDouble.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toFiniteDouble.apply, you'll get a compiler error that suggests you use a different factor method,FiniteDouble.from, instead:scala> val x = 1.1 x: Double = 1.1 scala> FiniteDouble(x) <console>:15: error: FiniteDouble.apply can only be invoked on a floating point literal, like FiniteDouble(1.1). Please use FiniteDouble.from instead. FiniteDouble(x) ^The FiniteDouble.fromfactory method will inspect the value at runtime and return anOption[FiniteDouble]. If the value is valid,FiniteDouble.fromwill return aSome[FiniteDouble], else it will return aNone. Here's an example:scala> FiniteDouble.from(x) res4: Option[org.scalactic.anyvals.FiniteDouble] = Some(FiniteDouble(1.1)) scala> val y = Finite.PositiveInfinity y: Double = Finite.PositiveInfinity scala> FiniteDouble.from(y) res5: Option[org.scalactic.anyvals.FiniteDouble] = None The FiniteDouble.applyfactory method is marked implicit, so that you can pass literalDoubles into methods that requireFiniteDouble, and get the same compile-time checking you get when callingFiniteDouble.applyexplicitly. Here's an example:scala> def invert(pos: FiniteDouble): Double = Double.MaxValue - pos invert: (pos: org.scalactic.anyvals.FiniteDouble)Double scala> invert(1.1) res6: Double = 1.7976931348623157E308 scala> invert(Double.MaxValue) res8: Double = 0.0 scala> invert(Finite.PositiveInfinity) <console>:15: error: FiniteDouble.apply can only be invoked on a finite (i != Double.NegativeInfinity && i != Double.PositiveInfinity && !i.isNaN) floating point literal, like FiniteDouble(1.1). invert(Finite.PositiveInfinity) ^This example also demonstrates that the FiniteDoublecompanion object also defines implicit widening conversions when a similar conversion is provided in Scala. This makes it convenient to use aFiniteDoublewhere aDoubleis needed. An example is the subtraction in the body of theinvertmethod defined above,Double.MaxValue - pos. AlthoughDouble.MaxValueis aDouble, which has no-method that takes aFiniteDouble(the type ofpos), you can still subtractpos, because theFiniteDoublewill be implicitly widened toDouble.
-   final  class FiniteFloat extends AnyValAn AnyValfor finiteFloats.An AnyValfor finiteFloats.Because FiniteFloatis anAnyValit will usually be as efficient as anFloat, being boxed only when anFloatwould have been boxed.The FiniteFloat.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingFiniteFloat.applywith a literalFloatvalue will either produce a validFiniteFloatinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> FiniteFloat(42.1fF) res0: org.scalactic.anyvals.FiniteFloat = FiniteFloat(42.1f) scala> FiniteFloat(Float.PositiveInfinityF) <console>:14: error: FiniteFloat.apply can only be invoked on a finite (i != Float.NegativeInfinity && i != Float.PositiveInfinity && !i.isNaN) floating point literal, like FiniteFloat(42.1fF). FiniteFloat(42.1fF) ^FiniteFloat.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toFiniteFloat.apply, you'll get a compiler error that suggests you use a different factor method,FiniteFloat.from, instead:scala> val x = 42.1fF x: Float = 42.1f scala> FiniteFloat(x) <console>:15: error: FiniteFloat.apply can only be invoked on a floating point literal, like FiniteFloat(42.1fF). Please use FiniteFloat.from instead. FiniteFloat(x) ^The FiniteFloat.fromfactory method will inspect the value at runtime and return anOption[FiniteFloat]. If the value is valid,FiniteFloat.fromwill return aSome[FiniteFloat], else it will return aNone. Here's an example:scala> FiniteFloat.from(x) res3: Option[org.scalactic.anyvals.FiniteFloat] = Some(FiniteFloat(42.1f)) scala> val y = Float.PositiveInfinityF y: Float = Float.PositiveInfinity scala> FiniteFloat.from(y) res4: Option[org.scalactic.anyvals.FiniteFloat] = None The FiniteFloat.applyfactory method is marked implicit, so that you can pass literalFloats into methods that requireFiniteFloat, and get the same compile-time checking you get when callingFiniteFloat.applyexplicitly. Here's an example:scala> def invert(pos: FiniteFloat): Float = Float.MaxValue - pos invert: (pos: org.scalactic.anyvals.FiniteFloat)Float scala> invert(42.1fF) res5: Float = 3.4028235E38 scala> invert(Float.MaxValue) res6: Float = 0.0 scala> invert(Float.PositiveInfinityF) <console>:15: error: FiniteFloat.apply can only be invoked on a finite (i != Float.NegativeInfinity && i != Float.PositiveInfinity && !i.isNaN) floating point literal, like FiniteFloat(42.1fF). invert(0.0F) ^ scala> invert(Float.PositiveInfinityF) <console>:15: error: FiniteFloat.apply can only be invoked on a finite (i != Float.NegativeInfinity && i != Float.PositiveInfinity && !i.isNaN) floating point literal, like FiniteFloat(42.1fF). invert(Float.PositiveInfinityF) ^This example also demonstrates that the FiniteFloatcompanion object also defines implicit widening conversions when no loss of precision will occur. This makes it convenient to use aFiniteFloatwhere aFloator wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Float.MaxValue - pos. AlthoughFloat.MaxValueis aFloat, which has no-method that takes aFiniteFloat(the type ofpos), you can still subtractpos, because theFiniteFloatwill be implicitly widened toFloat.
-   final  class NegDouble extends AnyValAn AnyValfor negativeDoubles.An AnyValfor negativeDoubles.Because NegDoubleis anAnyValit will usually be as efficient as anDouble, being boxed only when aDoublewould have been boxed.The NegDouble.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNegDouble.applywith a literalDoublevalue will either produce a validNegDoubleinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NegDouble(-1.1) res1: org.scalactic.anyvals.NegDouble = NegDouble(-1.1) scala> NegDouble(1.1) <console>:14: error: NegDouble.apply can only be invoked on a negative (i < 0.0) floating point literal, like NegDouble(-1.1). NegDouble(1.1) ^NegDouble.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNegDouble.apply, you'll get a compiler error that suggests you use a different factor method,NegDouble.from, instead:scala> val x = -1.1 x: Double = -1.1 scala> NegDouble(x) <console>:15: error: NegDouble.apply can only be invoked on a floating point literal, like NegDouble(-1.1). Please use NegDouble.from instead. NegDouble(x) ^The NegDouble.fromfactory method will inspect the value at runtime and return anOption[NegDouble]. If the value is valid,NegDouble.fromwill return aSome[NegDouble], else it will return aNone. Here's an example:scala> NegDouble.from(x) res4: Option[org.scalactic.anyvals.NegDouble] = Some(NegDouble(-1.1)) scala> val y = 1.1 y: Double = 1.1 scala> NegDouble.from(y) res5: Option[org.scalactic.anyvals.NegDouble] = None The NegDouble.applyfactory method is marked implicit, so that you can pass literalDoubles into methods that requireNegDouble, and get the same compile-time checking you get when callingNegDouble.applyexplicitly. Here's an example:scala> def invert(pos: NegDouble): Double = Double.MaxValue - pos invert: (pos: org.scalactic.anyvals.NegDouble)Double scala> invert(1.1) res6: Double = 1.7976931348623157E308 scala> invert(Double.MaxValue) res8: Double = 0.0 scala> invert(1.1) <console>:15: error: NegDouble.apply can only be invoked on a negative (i < 0.0) floating point literal, like NegDouble(-1.1). invert(1.1) ^This example also demonstrates that the NegDoublecompanion object also defines implicit widening conversions when a similar conversion is provided in Scala. This makes it convenient to use aNegDoublewhere aDoubleis needed. An example is the subtraction in the body of theinvertmethod defined above,Double.MaxValue - pos. AlthoughDouble.MaxValueis aDouble, which has no-method that takes aNegDouble(the type ofpos), you can still subtractpos, because theNegDoublewill be implicitly widened toDouble.
-   final  class NegFiniteDouble extends AnyValAn AnyValfor finite negativeDoubles.An AnyValfor finite negativeDoubles.Because NegFiniteDoubleis anAnyValit will usually be as efficient as anDouble, being boxed only when aDoublewould have been boxed.The NegFiniteDouble.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNegFiniteDouble.applywith a literalDoublevalue will either produce a validNegFiniteDoubleinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NegFiniteDouble(-1.1) res1: org.scalactic.anyvals.NegFiniteDouble = NegFiniteDouble(-1.1) scala> NegFiniteDouble(1.1) <console>:14: error: NegFiniteDouble.apply can only be invoked on a finite negative (i < 0.0 && i != Double.NegativeInfinity) floating point literal, like NegFiniteDouble(-1.1). NegFiniteDouble(1.1) ^NegFiniteDouble.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNegFiniteDouble.apply, you'll get a compiler error that suggests you use a different factor method,NegFiniteDouble.from, instead:scala> val x = -1.1 x: Double = -1.1 scala> NegFiniteDouble(x) <console>:15: error: NegFiniteDouble.apply can only be invoked on a floating point literal, like NegFiniteDouble(-1.1). Please use NegFiniteDouble.from instead. NegFiniteDouble(x) ^The NegFiniteDouble.fromfactory method will inspect the value at runtime and return anOption[NegFiniteDouble]. If the value is valid,NegFiniteDouble.fromwill return aSome[NegFiniteDouble], else it will return aNone. Here's an example:scala> NegFiniteDouble.from(x) res4: Option[org.scalactic.anyvals.NegFiniteDouble] = Some(NegFiniteDouble(-1.1)) scala> val y = 1.1 y: Double = 1.1 scala> NegFiniteDouble.from(y) res5: Option[org.scalactic.anyvals.NegFiniteDouble] = None The NegFiniteDouble.applyfactory method is marked implicit, so that you can pass literalDoubles into methods that requireNegFiniteDouble, and get the same compile-time checking you get when callingNegFiniteDouble.applyexplicitly. Here's an example:scala> def invert(pos: NegFiniteDouble): Double = Double.MaxValue - pos invert: (pos: org.scalactic.anyvals.NegFiniteDouble)Double scala> invert(1.1) res6: Double = 1.7976931348623157E308 scala> invert(Double.MaxValue) res8: Double = 0.0 scala> invert(1.1) <console>:15: error: NegFiniteDouble.apply can only be invoked on a finite negative (i < 0.0 && i != Double.NegativeInfinity) floating point literal, like NegFiniteDouble(-1.1). invert(1.1) ^This example also demonstrates that the NegFiniteDoublecompanion object also defines implicit widening conversions when a similar conversion is provided in Scala. This makes it convenient to use aNegFiniteDoublewhere aDoubleis needed. An example is the subtraction in the body of theinvertmethod defined above,Double.MaxValue - pos. AlthoughDouble.MaxValueis aDouble, which has no-method that takes aNegFiniteDouble(the type ofpos), you can still subtractpos, because theNegFiniteDoublewill be implicitly widened toDouble.
-   final  class NegFiniteFloat extends AnyValAn AnyValfor finite negativeFloats.An AnyValfor finite negativeFloats.Note: a NegFiniteFloatmay not equal 0.0. If you want negative number or 0, use NegZFiniteFloat.Because NegFiniteFloatis anAnyValit will usually be as efficient as anFloat, being boxed only when anFloatwould have been boxed.The NegFiniteFloat.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNegFiniteFloat.applywith a literalFloatvalue will either produce a validNegFiniteFloatinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NegFiniteFloat(-42.1fF) res0: org.scalactic.anyvals.NegFiniteFloat = NegFiniteFloat(-42.1f) scala> NegFiniteFloat(0.0fF) <console>:14: error: NegFiniteFloat.apply can only be invoked on a finite negative (i < 0.0f && i != Float.NegativeInfinity) floating point literal, like NegFiniteFloat(-42.1fF). NegFiniteFloat(-42.1fF) ^NegFiniteFloat.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNegFiniteFloat.apply, you'll get a compiler error that suggests you use a different factor method,NegFiniteFloat.from, instead:scala> val x = -42.1fF x: Float = -42.1f scala> NegFiniteFloat(x) <console>:15: error: NegFiniteFloat.apply can only be invoked on a floating point literal, like NegFiniteFloat(-42.1fF). Please use NegFiniteFloat.from instead. NegFiniteFloat(x) ^The NegFiniteFloat.fromfactory method will inspect the value at runtime and return anOption[NegFiniteFloat]. If the value is valid,NegFiniteFloat.fromwill return aSome[NegFiniteFloat], else it will return aNone. Here's an example:scala> NegFiniteFloat.from(x) res3: Option[org.scalactic.anyvals.NegFiniteFloat] = Some(NegFiniteFloat(-42.1f)) scala> val y = 0.0fF y: Float = 0.0f scala> NegFiniteFloat.from(y) res4: Option[org.scalactic.anyvals.NegFiniteFloat] = None The NegFiniteFloat.applyfactory method is marked implicit, so that you can pass literalFloats into methods that requireNegFiniteFloat, and get the same compile-time checking you get when callingNegFiniteFloat.applyexplicitly. Here's an example:scala> def invert(pos: NegFiniteFloat): Float = Float.MaxValue - pos invert: (pos: org.scalactic.anyvals.NegFiniteFloat)Float scala> invert(-42.1fF) res5: Float = 3.4028235E38 scala> invert(Float.MaxValue) res6: Float = 0.0 scala> invert(0.0fF) <console>:15: error: NegFiniteFloat.apply can only be invoked on a finite negative (i < 0.0f && i != Float.NegativeInfinity) floating point literal, like NegFiniteFloat(-42.1fF). invert(0.0F) ^ scala> invert(0.0fF) <console>:15: error: NegFiniteFloat.apply can only be invoked on a finite negative (i < 0.0f && i != Float.NegativeInfinity) floating point literal, like NegFiniteFloat(-42.1fF). invert(0.0fF) ^This example also demonstrates that the NegFiniteFloatcompanion object also defines implicit widening conversions when no loss of precision will occur. This makes it convenient to use aNegFiniteFloatwhere aFloator wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Float.MaxValue - pos. AlthoughFloat.MaxValueis aFloat, which has no-method that takes aNegFiniteFloat(the type ofpos), you can still subtractpos, because theNegFiniteFloatwill be implicitly widened toFloat.
-   final  class NegFloat extends AnyValAn AnyValfor megativeFloats.An AnyValfor megativeFloats.Note: a NegFloatmay not equal 0.0. If you want negative number or 0, use NegZFloat.Because NegFloatis anAnyValit will usually be as efficient as anFloat, being boxed only when anFloatwould have been boxed.The NegFloat.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNegFloat.applywith a literalFloatvalue will either produce a validNegFloatinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NegFloat(-42.1fF) res0: org.scalactic.anyvals.NegFloat = NegFloat(-42.1f) scala> NegFloat(0.0fF) <console>:14: error: NegFloat.apply can only be invoked on a megative (i < 0.0f) floating point literal, like NegFloat(-42.1fF). NegFloat(-42.1fF) ^NegFloat.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNegFloat.apply, you'll get a compiler error that suggests you use a different factor method,NegFloat.from, instead:scala> val x = -42.1fF x: Float = -42.1f scala> NegFloat(x) <console>:15: error: NegFloat.apply can only be invoked on a floating point literal, like NegFloat(-42.1fF). Please use NegFloat.from instead. NegFloat(x) ^The NegFloat.fromfactory method will inspect the value at runtime and return anOption[NegFloat]. If the value is valid,NegFloat.fromwill return aSome[NegFloat], else it will return aNone. Here's an example:scala> NegFloat.from(x) res3: Option[org.scalactic.anyvals.NegFloat] = Some(NegFloat(-42.1f)) scala> val y = 0.0fF y: Float = 0.0f scala> NegFloat.from(y) res4: Option[org.scalactic.anyvals.NegFloat] = None The NegFloat.applyfactory method is marked implicit, so that you can pass literalFloats into methods that requireNegFloat, and get the same compile-time checking you get when callingNegFloat.applyexplicitly. Here's an example:scala> def invert(pos: NegFloat): Float = Float.MaxValue - pos invert: (pos: org.scalactic.anyvals.NegFloat)Float scala> invert(-42.1fF) res5: Float = 3.4028235E38 scala> invert(Float.MaxValue) res6: Float = 0.0 scala> invert(0.0fF) <console>:15: error: NegFloat.apply can only be invoked on a megative (i < 0.0f) floating point literal, like NegFloat(-42.1fF). invert(0.0F) ^ scala> invert(0.0fF) <console>:15: error: NegFloat.apply can only be invoked on a megative (i < 0.0f) floating point literal, like NegFloat(-42.1fF). invert(0.0fF) ^This example also demonstrates that the NegFloatcompanion object also defines implicit widening conversions when no loss of precision will occur. This makes it convenient to use aNegFloatwhere aFloator wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Float.MaxValue - pos. AlthoughFloat.MaxValueis aFloat, which has no-method that takes aNegFloat(the type ofpos), you can still subtractpos, because theNegFloatwill be implicitly widened toFloat.
-   final  class NegInt extends AnyValAn AnyValfor negativeInts.An AnyValfor negativeInts.Note: a NegIntmay not equal 0. If you want negative number or 0, use NegZInt.Because NegIntis anAnyValit will usually be as efficient as anInt, being boxed only when anIntwould have been boxed.The NegInt.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNegInt.applywith a literalIntvalue will either produce a validNegIntinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NegInt(-42) res0: org.scalactic.anyvals.NegInt = NegInt(-42) scala> NegInt(0) <console>:14: error: NegInt.apply can only be invoked on a negative (i < 0) literal, like NegInt(-42). NegInt(0) ^NegInt.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNegInt.apply, you'll get a compiler error that suggests you use a different factor method,NegInt.from, instead:scala> val x = 1 x: Int = 1 scala> NegInt(x) <console>:15: error: NegInt.apply can only be invoked on a negative integer literal, like NegInt(-42). Please use NegInt.from instead. NegInt(x) ^The NegInt.fromfactory method will inspect the value at runtime and return anOption[NegInt]. If the value is valid,NegInt.fromwill return aSome[NegInt], else it will return aNone. Here's an example:scala> NegInt.from(x) res3: Option[org.scalactic.anyvals.NegInt] = Some(NegInt(1)) scala> val y = 0 y: Int = 0 scala> NegInt.from(y) res4: Option[org.scalactic.anyvals.NegInt] = None The NegInt.applyfactory method is marked implicit, so that you can pass literalInts into methods that requireNegInt, and get the same compile-time checking you get when callingNegInt.applyexplicitly. Here's an example:scala> def invert(pos: NegInt): Int = Int.MaxValue - pos invert: (pos: org.scalactic.anyvals.NegInt)Int scala> invert(1) res0: Int = 2147483646 scala> invert(Int.MaxValue) res1: Int = 0 scala> invert(0) <console>:15: error: NegInt.apply can only be invoked on a negative (i < 0) integer literal, like NegInt(-42). invert(0) ^ scala> invert(-1) <console>:15: error: NegInt.apply can only be invoked on a negative (i < 0) integer literal, like NegInt(-42). invert(-1) ^This example also demonstrates that the NegIntcompanion object also defines implicit widening conversions when either no loss of precision will occur or a similar conversion is provided in Scala. (For example, the implicit conversion fromIntto Float in Scala can lose precision.) This makes it convenient to use aNegIntwhere anIntor wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Int.MaxValue - pos. AlthoughInt.MaxValueis anInt, which has no-method that takes aNegInt(the type ofpos), you can still subtractpos, because theNegIntwill be implicitly widened toInt.
-   final  class NegLong extends AnyValAn AnyValfor negativeLongs.An AnyValfor negativeLongs.Note: a NegLongmay not equal 0. If you want negative number or 0, use NegZLong.Because NegLongis anAnyValit will usually be as efficient as anLong, being boxed only when anLongwould have been boxed.The NegLong.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNegLong.applywith a literalLongvalue will either produce a validNegLonginstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NegLong(-42L) res0: org.scalactic.anyvals.NegLong = NegLong(-42L) scala> NegLong(0L) <console>:14: error: NegLong.apply can only be invoked on a negative (i < 0L) integer literal, like NegLong(-42L). NegLong(0L) ^NegLong.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNegLong.apply, you'll get a compiler error that suggests you use a different factor method,NegLong.from, instead:scala> val x = -42LL x: Long = -42L scala> NegLong(x) <console>:15: error: NegLong.apply can only be invoked on an long literal, like NegLong(-42L). Please use NegLong.from instead. NegLong(x) ^The NegLong.fromfactory method will inspect the value at runtime and return anOption[NegLong]. If the value is valid,NegLong.fromwill return aSome[NegLong], else it will return aNone. Here's an example:scala> NegLong.from(x) res3: Option[org.scalactic.anyvals.NegLong] = Some(NegLong(-42L)) scala> val y = 0LL y: Long = 0L scala> NegLong.from(y) res4: Option[org.scalactic.anyvals.NegLong] = None The NegLong.applyfactory method is marked implicit, so that you can pass literalLongs into methods that requireNegLong, and get the same compile-time checking you get when callingNegLong.applyexplicitly. Here's an example:scala> def invert(pos: NegLong): Long = Long.MaxValue - pos invert: (pos: org.scalactic.anyvals.NegLong)Long scala> invert(1L) res5: Long = 9223372036854775806 scala> invert(Long.MaxValue) res6: Long = 0 scala> invert(0LL) <console>:15: error: NegLong.apply can only be invoked on a negative (i < 0L) integer literal, like NegLong(-42LL). invert(0LL) ^This example also demonstrates that the NegLongcompanion object also defines implicit widening conversions when either no loss of precision will occur or a similar conversion is provided in Scala. (For example, the implicit conversion fromLongto Double in Scala can lose precision.) This makes it convenient to use aNegLongwhere aLongor wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Long.MaxValue - pos. AlthoughLong.MaxValueis aLong, which has no-method that takes aNegLong(the type ofpos), you can still subtractpos, because theNegLongwill be implicitly widened toLong.
-   final  class NegZDouble extends AnyValAn AnyValfor non-positiveDoubles.An AnyValfor non-positiveDoubles.Because NegZDoubleis anAnyValit will usually be as efficient as anDouble, being boxed only when aDoublewould have been boxed.The NegZDouble.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNegZDouble.applywith a literalDoublevalue will either produce a validNegZDoubleinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NegZDouble(-1.1) res1: org.scalactic.anyvals.NegZDouble = NegZDouble(-1.1) scala> NegZDouble(1.1) <console>:14: error: NegZDouble.apply can only be invoked on a non-positive (i <= 0.0) floating point literal, like NegZDouble(-1.1). NegZDouble(1.1) ^NegZDouble.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNegZDouble.apply, you'll get a compiler error that suggests you use a different factor method,NegZDouble.from, instead:scala> val x = -1.1 x: Double = -1.1 scala> NegZDouble(x) <console>:15: error: NegZDouble.apply can only be invoked on a floating point literal, like NegZDouble(-1.1). Please use NegZDouble.from instead. NegZDouble(x) ^The NegZDouble.fromfactory method will inspect the value at runtime and return anOption[NegZDouble]. If the value is valid,NegZDouble.fromwill return aSome[NegZDouble], else it will return aNone. Here's an example:scala> NegZDouble.from(x) res4: Option[org.scalactic.anyvals.NegZDouble] = Some(NegZDouble(-1.1)) scala> val y = 1.1 y: Double = 1.1 scala> NegZDouble.from(y) res5: Option[org.scalactic.anyvals.NegZDouble] = None The NegZDouble.applyfactory method is marked implicit, so that you can pass literalDoubles into methods that requireNegZDouble, and get the same compile-time checking you get when callingNegZDouble.applyexplicitly. Here's an example:scala> def invert(pos: NegZDouble): Double = Double.MaxValue - pos invert: (pos: org.scalactic.anyvals.NegZDouble)Double scala> invert(1.1) res6: Double = 1.7976931348623157E308 scala> invert(Double.MaxValue) res8: Double = 0.0 scala> invert(1.1) <console>:15: error: NegZDouble.apply can only be invoked on a non-positive (i <= 0.0) floating point literal, like NegZDouble(-1.1). invert(1.1) ^This example also demonstrates that the NegZDoublecompanion object also defines implicit widening conversions when a similar conversion is provided in Scala. This makes it convenient to use aNegZDoublewhere aDoubleis needed. An example is the subtraction in the body of theinvertmethod defined above,Double.MaxValue - pos. AlthoughDouble.MaxValueis aDouble, which has no-method that takes aNegZDouble(the type ofpos), you can still subtractpos, because theNegZDoublewill be implicitly widened toDouble.
-   final  class NegZFiniteDouble extends AnyValAn AnyValfor finite non-positiveDoubles.An AnyValfor finite non-positiveDoubles.Because NegZFiniteDoubleis anAnyValit will usually be as efficient as anDouble, being boxed only when aDoublewould have been boxed.The NegZFiniteDouble.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNegZFiniteDouble.applywith a literalDoublevalue will either produce a validNegZFiniteDoubleinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NegZFiniteDouble(-1.1) res1: org.scalactic.anyvals.NegZFiniteDouble = NegZFiniteDouble(-1.1) scala> NegZFiniteDouble(1.1) <console>:14: error: NegZFiniteDouble.apply can only be invoked on a finite non-positive (i <= 0.0 && i != Double.NegativeInfinity) floating point literal, like NegZFiniteDouble(-1.1). NegZFiniteDouble(1.1) ^NegZFiniteDouble.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNegZFiniteDouble.apply, you'll get a compiler error that suggests you use a different factor method,NegZFiniteDouble.from, instead:scala> val x = -1.1 x: Double = -1.1 scala> NegZFiniteDouble(x) <console>:15: error: NegZFiniteDouble.apply can only be invoked on a floating point literal, like NegZFiniteDouble(-1.1). Please use NegZFiniteDouble.from instead. NegZFiniteDouble(x) ^The NegZFiniteDouble.fromfactory method will inspect the value at runtime and return anOption[NegZFiniteDouble]. If the value is valid,NegZFiniteDouble.fromwill return aSome[NegZFiniteDouble], else it will return aNone. Here's an example:scala> NegZFiniteDouble.from(x) res4: Option[org.scalactic.anyvals.NegZFiniteDouble] = Some(NegZFiniteDouble(-1.1)) scala> val y = 1.1 y: Double = 1.1 scala> NegZFiniteDouble.from(y) res5: Option[org.scalactic.anyvals.NegZFiniteDouble] = None The NegZFiniteDouble.applyfactory method is marked implicit, so that you can pass literalDoubles into methods that requireNegZFiniteDouble, and get the same compile-time checking you get when callingNegZFiniteDouble.applyexplicitly. Here's an example:scala> def invert(pos: NegZFiniteDouble): Double = Double.MaxValue - pos invert: (pos: org.scalactic.anyvals.NegZFiniteDouble)Double scala> invert(1.1) res6: Double = 1.7976931348623157E308 scala> invert(Double.MaxValue) res8: Double = 0.0 scala> invert(1.1) <console>:15: error: NegZFiniteDouble.apply can only be invoked on a finite non-positive (i <= 0.0 && i != Double.NegativeInfinity) floating point literal, like NegZFiniteDouble(-1.1). invert(1.1) ^This example also demonstrates that the NegZFiniteDoublecompanion object also defines implicit widening conversions when a similar conversion is provided in Scala. This makes it convenient to use aNegZFiniteDoublewhere aDoubleis needed. An example is the subtraction in the body of theinvertmethod defined above,Double.MaxValue - pos. AlthoughDouble.MaxValueis aDouble, which has no-method that takes aNegZFiniteDouble(the type ofpos), you can still subtractpos, because theNegZFiniteDoublewill be implicitly widened toDouble.
-   final  class NegZFiniteFloat extends AnyValAn AnyValfor finite non-positiveFloats.An AnyValfor finite non-positiveFloats.Because NegZFiniteFloatis anAnyValit will usually be as efficient as anFloat, being boxed only when anFloatwould have been boxed.The NegZFiniteFloat.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNegZFiniteFloat.applywith a literalFloatvalue will either produce a validNegZFiniteFloatinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NegZFiniteFloat(-1.1fF) res0: org.scalactic.anyvals.NegZFiniteFloat = NegZFiniteFloat(-1.1f) scala> NegZFiniteFloat(1.1fF) <console>:14: error: NegZFiniteFloat.apply can only be invoked on a finite non-positive (i <= 0.0f && i != Float.NegativeInfinity) floating point literal, like NegZFiniteFloat(-1.1fF). NegZFiniteFloat(-1.1fF) ^NegZFiniteFloat.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNegZFiniteFloat.apply, you'll get a compiler error that suggests you use a different factor method,NegZFiniteFloat.from, instead:scala> val x = -1.1fF x: Float = -1.1f scala> NegZFiniteFloat(x) <console>:15: error: NegZFiniteFloat.apply can only be invoked on a floating point literal, like NegZFiniteFloat(-1.1fF). Please use NegZFiniteFloat.from instead. NegZFiniteFloat(x) ^The NegZFiniteFloat.fromfactory method will inspect the value at runtime and return anOption[NegZFiniteFloat]. If the value is valid,NegZFiniteFloat.fromwill return aSome[NegZFiniteFloat], else it will return aNone. Here's an example:scala> NegZFiniteFloat.from(x) res3: Option[org.scalactic.anyvals.NegZFiniteFloat] = Some(NegZFiniteFloat(-1.1f)) scala> val y = 1.1fF y: Float = 1.1f scala> NegZFiniteFloat.from(y) res4: Option[org.scalactic.anyvals.NegZFiniteFloat] = None The NegZFiniteFloat.applyfactory method is marked implicit, so that you can pass literalFloats into methods that requireNegZFiniteFloat, and get the same compile-time checking you get when callingNegZFiniteFloat.applyexplicitly. Here's an example:scala> def invert(pos: NegZFiniteFloat): Float = Float.MaxValue - pos invert: (pos: org.scalactic.anyvals.NegZFiniteFloat)Float scala> invert(-1.1fF) res5: Float = 3.4028235E38 scala> invert(Float.MaxValue) res6: Float = 0.0 scala> invert(1.1fF) <console>:15: error: NegZFiniteFloat.apply can only be invoked on a finite non-positive (i <= 0.0f && i != Float.NegativeInfinity) floating point literal, like NegZFiniteFloat(-1.1fF). invert(0.0F) ^ scala> invert(1.1fF) <console>:15: error: NegZFiniteFloat.apply can only be invoked on a finite non-positive (i <= 0.0f && i != Float.NegativeInfinity) floating point literal, like NegZFiniteFloat(-1.1fF). invert(1.1fF) ^This example also demonstrates that the NegZFiniteFloatcompanion object also defines implicit widening conversions when no loss of precision will occur. This makes it convenient to use aNegZFiniteFloatwhere aFloator wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Float.MaxValue - pos. AlthoughFloat.MaxValueis aFloat, which has no-method that takes aNegZFiniteFloat(the type ofpos), you can still subtractpos, because theNegZFiniteFloatwill be implicitly widened toFloat.
-   final  class NegZFloat extends AnyValAn AnyValfor non-positiveFloats.An AnyValfor non-positiveFloats.Because NegZFloatis anAnyValit will usually be as efficient as anFloat, being boxed only when anFloatwould have been boxed.The NegZFloat.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNegZFloat.applywith a literalFloatvalue will either produce a validNegZFloatinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NegZFloat(-1.1fF) res0: org.scalactic.anyvals.NegZFloat = NegZFloat(-1.1f) scala> NegZFloat(1.1fF) <console>:14: error: NegZFloat.apply can only be invoked on a non-positive (i <= 0.0f) floating point literal, like NegZFloat(-1.1fF). NegZFloat(-1.1fF) ^NegZFloat.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNegZFloat.apply, you'll get a compiler error that suggests you use a different factor method,NegZFloat.from, instead:scala> val x = -1.1fF x: Float = -1.1f scala> NegZFloat(x) <console>:15: error: NegZFloat.apply can only be invoked on a floating point literal, like NegZFloat(-1.1fF). Please use NegZFloat.from instead. NegZFloat(x) ^The NegZFloat.fromfactory method will inspect the value at runtime and return anOption[NegZFloat]. If the value is valid,NegZFloat.fromwill return aSome[NegZFloat], else it will return aNone. Here's an example:scala> NegZFloat.from(x) res3: Option[org.scalactic.anyvals.NegZFloat] = Some(NegZFloat(-1.1f)) scala> val y = 1.1fF y: Float = 1.1f scala> NegZFloat.from(y) res4: Option[org.scalactic.anyvals.NegZFloat] = None The NegZFloat.applyfactory method is marked implicit, so that you can pass literalFloats into methods that requireNegZFloat, and get the same compile-time checking you get when callingNegZFloat.applyexplicitly. Here's an example:scala> def invert(pos: NegZFloat): Float = Float.MaxValue - pos invert: (pos: org.scalactic.anyvals.NegZFloat)Float scala> invert(-1.1fF) res5: Float = 3.4028235E38 scala> invert(Float.MaxValue) res6: Float = 0.0 scala> invert(1.1fF) <console>:15: error: NegZFloat.apply can only be invoked on a non-positive (i <= 0.0f) floating point literal, like NegZFloat(-1.1fF). invert(0.0F) ^ scala> invert(1.1fF) <console>:15: error: NegZFloat.apply can only be invoked on a non-positive (i <= 0.0f) floating point literal, like NegZFloat(-1.1fF). invert(1.1fF) ^This example also demonstrates that the NegZFloatcompanion object also defines implicit widening conversions when no loss of precision will occur. This makes it convenient to use aNegZFloatwhere aFloator wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Float.MaxValue - pos. AlthoughFloat.MaxValueis aFloat, which has no-method that takes aNegZFloat(the type ofpos), you can still subtractpos, because theNegZFloatwill be implicitly widened toFloat.
-   final  class NegZInt extends AnyValAn AnyValfor non-positiveInts.An AnyValfor non-positiveInts.Because NegZIntis anAnyValit will usually be as efficient as anInt, being boxed only when anIntwould have been boxed.The NegZInt.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNegZInt.applywith a literalIntvalue will either produce a validNegZIntinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NegZInt(-42) res0: org.scalactic.anyvals.NegZInt = NegZInt(-42) scala> NegZInt(1) <console>:14: error: NegZInt.apply can only be invoked on a non-positive (i <= 0) literal, like NegZInt(-42). NegZInt(1) ^NegZInt.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNegZInt.apply, you'll get a compiler error that suggests you use a different factor method,NegZInt.from, instead:scala> val x = 1 x: Int = 1 scala> NegZInt(x) <console>:15: error: NegZInt.apply can only be invoked on a non-positive integer literal, like NegZInt(-42). Please use NegZInt.from instead. NegZInt(x) ^The NegZInt.fromfactory method will inspect the value at runtime and return anOption[NegZInt]. If the value is valid,NegZInt.fromwill return aSome[NegZInt], else it will return aNone. Here's an example:scala> NegZInt.from(x) res3: Option[org.scalactic.anyvals.NegZInt] = Some(NegZInt(1)) scala> val y = 0 y: Int = 0 scala> NegZInt.from(y) res4: Option[org.scalactic.anyvals.NegZInt] = None The NegZInt.applyfactory method is marked implicit, so that you can pass literalInts into methods that requireNegZInt, and get the same compile-time checking you get when callingNegZInt.applyexplicitly. Here's an example:scala> def invert(pos: NegZInt): Int = Int.MaxValue - pos invert: (pos: org.scalactic.anyvals.NegZInt)Int scala> invert(1) res0: Int = 2147483646 scala> invert(Int.MaxValue) res1: Int = 0 scala> invert(0) <console>:15: error: NegZInt.apply can only be invoked on a non-positive (i <= 0) integer literal, like NegZInt(-42). invert(0) ^ scala> invert(-1) <console>:15: error: NegZInt.apply can only be invoked on a non-positive (i <= 0) integer literal, like NegZInt(-42). invert(-1) ^This example also demonstrates that the NegZIntcompanion object also defines implicit widening conversions when either no loss of precision will occur or a similar conversion is provided in Scala. (For example, the implicit conversion fromIntto Float in Scala can lose precision.) This makes it convenient to use aNegZIntwhere anIntor wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Int.MaxValue - pos. AlthoughInt.MaxValueis anInt, which has no-method that takes aNegZInt(the type ofpos), you can still subtractpos, because theNegZIntwill be implicitly widened toInt.
-   final  class NegZLong extends AnyValAn AnyValfor non-positiveLongs.An AnyValfor non-positiveLongs.Because NegZLongis anAnyValit will usually be as efficient as anLong, being boxed only when anLongwould have been boxed.The NegZLong.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNegZLong.applywith a literalLongvalue will either produce a validNegZLonginstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NegZLong(-42L) res0: org.scalactic.anyvals.NegZLong = NegZLong(-42L) scala> NegZLong(-1L) <console>:14: error: NegZLong.apply can only be invoked on a non-positive (i <= 0L) integer literal, like NegZLong(-42L). NegZLong(-1L) ^NegZLong.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNegZLong.apply, you'll get a compiler error that suggests you use a different factor method,NegZLong.from, instead:scala> val x = -42L x: Long = -42 scala> NegZLong(x) <console>:15: error: NegZLong.apply can only be invoked on an long literal, like NegZLong(-42L). Please use NegZLong.from instead. NegZLong(x) ^The NegZLong.fromfactory method will inspect the value at runtime and return anOption[NegZLong]. If the value is valid,NegZLong.fromwill return aSome[NegZLong], else it will return aNone. Here's an example:scala> NegZLong.from(x) res3: Option[org.scalactic.anyvals.NegZLong] = Some(NegZLong(-42)) scala> val y = 1L y: Long = 1 scala> NegZLong.from(y) res4: Option[org.scalactic.anyvals.NegZLong] = None The NegZLong.applyfactory method is marked implicit, so that you can pass literalLongs into methods that requireNegZLong, and get the same compile-time checking you get when callingNegZLong.applyexplicitly. Here's an example:scala> def invert(pos: NegZLong): Long = Long.MaxValue - pos invert: (pos: org.scalactic.anyvals.NegZLong)Long scala> invert(1L) res5: Long = 9223372036854775806 scala> invert(Long.MaxValue) res6: Long = 0 scala> invert(1L) <console>:15: error: NegZLong.apply can only be invoked on a non-positive (i <= 0L) integer literal, like NegZLong(-42L). invert(1L) ^This example also demonstrates that the NegZLongcompanion object also defines implicit widening conversions when either no loss of precision will occur or a similar conversion is provided in Scala. (For example, the implicit conversion fromLongto Double in Scala can lose precision.) This makes it convenient to use aNegZLongwhere aLongor wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Long.MaxValue - pos. AlthoughLong.MaxValueis aLong, which has no-method that takes aNegZLong(the type ofpos), you can still subtractpos, because theNegZLongwill be implicitly widened toLong.
-   final  class NonEmptyArray[T] extends AnyValA non-empty array: an ordered, mutable, non-empty collection of elements with IndexedSeqperformance characteristics.A non-empty array: an ordered, mutable, non-empty collection of elements with IndexedSeqperformance characteristics.The purpose of NonEmptyArrayis to allow you to express in a type that anArrayis non-empty, thereby eliminating the need for (and potential exception from) a run-time check for non-emptiness. For a non-empty immutable sequence withIndexedSeqperformance, seeEvery.ConstructingNonEmptyArraysYou can construct a NonEmptyArrayby passing one or more elements to theNonEmptyArray.applyfactory method:scala> NonEmptyArray(1, 2, 3) res0: org.scalactic.anyvals.NonEmptyArray[Int] = NonEmptyArray(1, 2, 3) Working withNonEmptyArraysNonEmptyArraydoes not extend Scala'sSeqorTraversabletraits because these require that implementations may be empty. For example, if you invoketailon aSeqthat contains just one element, you'll get an emptySeq:scala> Array(1).tail res6: Array[Int] = Array() On the other hand, many useful methods exist on Seqthat when invoked on a non-emptySeqare guaranteed to not result in an emptySeq. For convenience,NonEmptyArraydefines a method corresponding to every suchSeqmethod. Here are some examples:NonEmptyArray(1, 2, 3).map(_ + 1) // Result: NonEmptyArray(2, 3, 4) NonEmptyArray(1).map(_ + 1) // Result: NonEmptyArray(2) NonEmptyArray(1, 2, 3).containsSlice(NonEmptyArray(2, 3)) // Result: true NonEmptyArray(1, 2, 3).containsSlice(NonEmptyArray(3, 4)) // Result: false NonEmptyArray(-1, -2, 3, 4, 5).minBy(_.abs) // Result: -1 NonEmptyArraydoes not currently define any methods corresponding toSeqmethods that could result in an emptySeq. However, an implicit converison fromNonEmptyArraytoArrayis defined in theNonEmptyArraycompanion object that will be applied if you attempt to call one of the missing methods. As a result, you can invokefilteron anNonEmptyArray, even thoughfiltercould result in an empty sequence—but the result type will beArrayinstead ofNonEmptyArray:NonEmptyArray(1, 2, 3).filter(_ < 10) // Result: Array(1, 2, 3) NonEmptyArray(1, 2, 3).filter(_ > 10) // Result: Array() You can use NonEmptyArrays inforexpressions. The result will be anNonEmptyArrayunless you use a filter (anifclause). Because filters are desugared to invocations offilter, the result type will switch to aArrayat that point. Here are some examples:scala> import org.scalactic.anyvals._ import org.scalactic.anyvals._ scala> for (i <- NonEmptyArray(1, 2, 3)) yield i + 1 res0: org.scalactic.anyvals.NonEmptyArray[Int] = NonEmptyArray(2, 3, 4) scala> for (i <- NonEmptyArray(1, 2, 3) if i < 10) yield i + 1 res1: Array[Int] = Array(2, 3, 4) scala> for { | i <- NonEmptyArray(1, 2, 3) | j <- NonEmptyArray('a', 'b', 'c') | } yield (i, j) res3: org.scalactic.anyvals.NonEmptyArray[(Int, Char)] = NonEmptyArray((1,a), (1,b), (1,c), (2,a), (2,b), (2,c), (3,a), (3,b), (3,c)) scala> for { | i <- NonEmptyArray(1, 2, 3) if i < 10 | j <- NonEmptyArray('a', 'b', 'c') | } yield (i, j) res6: Array[(Int, Char)] = Array((1,a), (1,b), (1,c), (2,a), (2,b), (2,c), (3,a), (3,b), (3,c))- T
- the type of elements contained in this - NonEmptyArray
 
-   final  class NonEmptyList[+T] extends AnyValA non-empty list: an ordered, immutable, non-empty collection of elements with LinearSeqperformance characteristics.A non-empty list: an ordered, immutable, non-empty collection of elements with LinearSeqperformance characteristics.The purpose of NonEmptyListis to allow you to express in a type that aListis non-empty, thereby eliminating the need for (and potential exception from) a run-time check for non-emptiness. For a non-empty sequence withIndexedSeqperformance, seeEvery.ConstructingNonEmptyListsYou can construct a NonEmptyListby passing one or more elements to theNonEmptyList.applyfactory method:scala> NonEmptyList(1, 2, 3) res0: org.scalactic.anyvals.NonEmptyList[Int] = NonEmptyList(1, 2, 3) Alternatively you can cons elements onto the Endsingleton object, similar to making aListstarting withNil:scala> 1 :: 2 :: 3 :: Nil res0: List[Int] = List(1, 2, 3) 
 scala> 1 :: 2 :: 3 :: End res1: org.scalactic.NonEmptyList[Int] = NonEmptyList(1, 2, 3)Note that although Nilis aList[Nothing],Endis not aNonEmptyList[Nothing], because no emptyNonEmptyListexists. (A non-empty list is a series of connected links; if you have no links, you have no non-empty list.)scala> val nil: List[Nothing] = Nil nil: List[Nothing] = List() 
 scala> val nada: NonEmptyList[Nothing] = End <console>:16: error: type mismatch; found : org.scalactic.anyvals.End.type required: org.scalactic.anyvals.NonEmptyList[Nothing] val nada: NonEmptyList[Nothing] = End ^Working withNonEmptyListsNonEmptyListdoes not extend Scala'sSeqorTraversabletraits because these require that implementations may be empty. For example, if you invoketailon aSeqthat contains just one element, you'll get an emptySeq:scala> List(1).tail res6: List[Int] = List() On the other hand, many useful methods exist on Seqthat when invoked on a non-emptySeqare guaranteed to not result in an emptySeq. For convenience,NonEmptyListdefines a method corresponding to every suchSeqmethod. Here are some examples:NonEmptyList(1, 2, 3).map(_ + 1) // Result: NonEmptyList(2, 3, 4) NonEmptyList(1).map(_ + 1) // Result: NonEmptyList(2) NonEmptyList(1, 2, 3).containsSlice(NonEmptyList(2, 3)) // Result: true NonEmptyList(1, 2, 3).containsSlice(NonEmptyList(3, 4)) // Result: false NonEmptyList(-1, -2, 3, 4, 5).minBy(_.abs) // Result: -1 NonEmptyListdoes not currently define any methods corresponding toSeqmethods that could result in an emptySeq. However, an implicit converison fromNonEmptyListtoListis defined in theNonEmptyListcompanion object that will be applied if you attempt to call one of the missing methods. As a result, you can invokefilteron anNonEmptyList, even thoughfiltercould result in an empty sequence—but the result type will beListinstead ofNonEmptyList:NonEmptyList(1, 2, 3).filter(_ < 10) // Result: List(1, 2, 3) NonEmptyList(1, 2, 3).filter(_ > 10) // Result: List() You can use NonEmptyLists inforexpressions. The result will be anNonEmptyListunless you use a filter (anifclause). Because filters are desugared to invocations offilter, the result type will switch to aListat that point. Here are some examples:scala> import org.scalactic.anyvals._ import org.scalactic.anyvals._ scala> for (i <- NonEmptyList(1, 2, 3)) yield i + 1 res0: org.scalactic.anyvals.NonEmptyList[Int] = NonEmptyList(2, 3, 4) scala> for (i <- NonEmptyList(1, 2, 3) if i < 10) yield i + 1 res1: List[Int] = List(2, 3, 4) scala> for { | i <- NonEmptyList(1, 2, 3) | j <- NonEmptyList('a', 'b', 'c') | } yield (i, j) res3: org.scalactic.anyvals.NonEmptyList[(Int, Char)] = NonEmptyList((1,a), (1,b), (1,c), (2,a), (2,b), (2,c), (3,a), (3,b), (3,c)) scala> for { | i <- NonEmptyList(1, 2, 3) if i < 10 | j <- NonEmptyList('a', 'b', 'c') | } yield (i, j) res6: List[(Int, Char)] = List((1,a), (1,b), (1,c), (2,a), (2,b), (2,c), (3,a), (3,b), (3,c))- T
- the type of elements contained in this - NonEmptyList
 
-   final  class NonEmptyMap[K, +V] extends AnyValA non-empty map: an ordered, immutable, non-empty collection of key-value tuples with LinearSeqperformance characteristics.A non-empty map: an ordered, immutable, non-empty collection of key-value tuples with LinearSeqperformance characteristics.The purpose of NonEmptyMapis to allow you to express in a type that aMapis non-empty, thereby eliminating the need for (and potential exception from) a run-time check for non-emptiness. For a non-empty sequence withIndexedSeqperformance, seeEvery.ConstructingNonEmptyMapsYou can construct a NonEmptyMapby passing one or more elements to theNonEmptyMap.applyfactory method:scala> NonEmptyMap(1 -> "one", 2 -> "two", 3 -> "three") res0: org.scalactic.anyvals.NonEmptyMap[Int, String] = NonEmptyMap(1 -> "one", 2 -> "two", 3 -> "three") Working withNonEmptyMapsNonEmptyMapdoes not extend Scala'sMaporTraversabletraits because these require that implementations may be empty. For example, if you invoketailon aSeqthat contains just one element, you'll get an emptySeq:scala> Map(1 -> "one").tail res6: Map[Int] = Map() On the other hand, many useful methods exist on Mapthat when invoked on a non-emptySeqare guaranteed to not result in an emptyMap. For convenience,NonEmptyMapdefines a method corresponding to every suchMapmethod. Here are an example:NonEmptyMap(1 -> "one", 2 -> "two", 3 -> "three").map(t => (t._1 + 1, t._2)) // Result: NonEmptyMap(2 -> "one", 3 -> "two", 4 -> "three") NonEmptyMapdoes not currently define any methods corresponding toMapmethods that could result in an emptyMap. However, an implicit converison fromNonEmptyMaptoMapis defined in theNonEmptyMapcompanion object that will be applied if you attempt to call one of the missing methods. As a result, you can invokefilteron anNonEmptyMap, even thoughfiltercould result in an empty map—but the result type will beMapinstead ofNonEmptyMap:NonEmptyMap(1 -> "one", 2 -> "two", 3 -> "three").filter(_._1 < 10) // Result: Map(1 -> "one", 2 -> "two", 3 -> "three") NonEmptyMap(1 -> "one", 2 -> "two", 3 -> "three").filter(_._ 1> 10) // Result: Map() You can use NonEmptyMaps inforexpressions. The result will be anNonEmptyMapunless you use a filter (anifclause). Because filters are desugared to invocations offilter, the result type will switch to aMapat that point. Here are some examples:scala> import org.scalactic.anyvals._ import org.scalactic.anyvals._ scala> for ((i, j) <- NonEmptyMap(1 -> "one", 2 -> "two", 3 -> "three")) yield (i + 1, j) res0: org.scalactic.anyvals.NonEmptyMap[Int, String] = NonEmptyMap(2 -> "one", 3 -> "two", 4 -> "three") scala> for ((i, j) <- NonEmptyMap(1, 2, 3) if i < 10) yield (i + 1, j) res1: Map[Int, String] = Map(2 -> "one", 3 -> "two", 4 -> "three") - K
- the type of key contained in this - NonEmptyMap
- V
- the type of value contained in this - NonEmptyMap
 
-   final  class NonEmptySet[T] extends AnyValA non-empty Set: an ordered, immutable, non-empty collection of elements with LinearSeqperformance characteristics.A non-empty Set: an ordered, immutable, non-empty collection of elements with LinearSeqperformance characteristics.The purpose of NonEmptySetis to allow you to express in a type that aSetis non-empty, thereby eliminating the need for (and potential exception from) a run-time check for non-emptiness. For a non-empty sequence withIndexedSeqperformance, seeEvery.ConstructingNonEmptySetsYou can construct a NonEmptySetby passing one or more elements to theNonEmptySet.applyfactory method:scala> NonEmptySet(1, 2, 3) res0: org.scalactic.anyvals.NonEmptySet[Int] = NonEmptySet(1, 2, 3) Alternatively you can cons elements onto the Endsingleton object, similar to making aSetstarting withNil:scala> 1 :: 2 :: 3 :: Nil res0: Set[Int] = Set(1, 2, 3) 
 scala> 1 :: 2 :: 3 :: End res1: org.scalactic.NonEmptySet[Int] = NonEmptySet(1, 2, 3)Note that although Nilis aSet[Nothing],Endis not aNonEmptySet[Nothing], because no emptyNonEmptySetexists. (A non-empty Set is a series of connected links; if you have no links, you have no non-empty Set.)scala> val nil: Set[Nothing] = Nil nil: Set[Nothing] = Set() 
 scala> val nada: NonEmptySet[Nothing] = End <console>:16: error: type mismatch; found : org.scalactic.anyvals.End.type required: org.scalactic.anyvals.NonEmptySet[Nothing] val nada: NonEmptySet[Nothing] = End ^Working withNonEmptySetsNonEmptySetdoes not extend Scala'sSeqorTraversabletraits because these require that implementations may be empty. For example, if you invoketailon aSeqthat contains just one element, you'll get an emptySeq:scala> Set(1).tail res6: Set[Int] = Set() On the other hand, many useful methods exist on Seqthat when invoked on a non-emptySeqare guaranteed to not result in an emptySeq. For convenience,NonEmptySetdefines a method corresponding to every suchSeqmethod. Here are some examples:NonEmptySet(1, 2, 3).map(_ + 1) // Result: NonEmptySet(2, 3, 4) NonEmptySet(1).map(_ + 1) // Result: NonEmptySet(2) NonEmptySet(1, 2, 3).containsSlice(NonEmptySet(2, 3)) // Result: true NonEmptySet(1, 2, 3).containsSlice(NonEmptySet(3, 4)) // Result: false NonEmptySet(-1, -2, 3, 4, 5).minBy(_.abs) // Result: -1 NonEmptySetdoes not currently define any methods corresponding toSeqmethods that could result in an emptySeq. However, an implicit converison fromNonEmptySettoSetis defined in theNonEmptySetcompanion object that will be applied if you attempt to call one of the missing methods. As a result, you can invokefilteron anNonEmptySet, even thoughfiltercould result in an empty sequence—but the result type will beSetinstead ofNonEmptySet:NonEmptySet(1, 2, 3).filter(_ < 10) // Result: Set(1, 2, 3) NonEmptySet(1, 2, 3).filter(_ > 10) // Result: Set() You can use NonEmptySets inforexpressions. The result will be anNonEmptySetunless you use a filter (anifclause). Because filters are desugared to invocations offilter, the result type will switch to aSetat that point. Here are some examples:scala> import org.scalactic.anyvals._ import org.scalactic.anyvals._ scala> for (i <- NonEmptySet(1, 2, 3)) yield i + 1 res0: org.scalactic.anyvals.NonEmptySet[Int] = NonEmptySet(2, 3, 4) scala> for (i <- NonEmptySet(1, 2, 3) if i < 10) yield i + 1 res1: Set[Int] = Set(2, 3, 4) scala> for { | i <- NonEmptySet(1, 2, 3) | j <- NonEmptySet('a', 'b', 'c') | } yield (i, j) res3: org.scalactic.anyvals.NonEmptySet[(Int, Char)] = NonEmptySet((1,a), (1,b), (1,c), (2,a), (2,b), (2,c), (3,a), (3,b), (3,c)) scala> for { | i <- NonEmptySet(1, 2, 3) if i < 10 | j <- NonEmptySet('a', 'b', 'c') | } yield (i, j) res6: Set[(Int, Char)] = Set((1,a), (1,b), (1,c), (2,a), (2,b), (2,c), (3,a), (3,b), (3,c))- T
- the type of elements contained in this - NonEmptySet
 
-   final  class NonEmptyString extends AnyValA non-empty list: an ordered, immutable, non-empty collection of elements with LinearSeqperformance characteristics.A non-empty list: an ordered, immutable, non-empty collection of elements with LinearSeqperformance characteristics.The purpose of NonEmptyStringis to allow you to express in a type that aStringis non-empty, thereby eliminating the need for (and potential exception from) a run-time check for non-emptiness. For a non-empty sequence withIndexedSeqperformance, seeEvery.ConstructingNonEmptyStringsYou can construct a NonEmptyStringby passing one or more elements to theNonEmptyString.applyfactory method:scala> NonEmptyString(1, 2, 3) res0: org.scalactic.anyvals.NonEmptyString[Int] = NonEmptyString(1, 2, 3) Alternatively you can cons elements onto the Endsingleton object, similar to making aStringstarting withNil:scala> 1 :: 2 :: 3 :: Nil res0: String[Int] = String(1, 2, 3) 
 scala> 1 :: 2 :: 3 :: End res1: org.scalactic.NonEmptyString[Int] = NonEmptyString(1, 2, 3)Note that although Nilis aString[Nothing],Endis not aNonEmptyString[Nothing], because no emptyNonEmptyStringexists. (A non-empty list is a series of connected links; if you have no links, you have no non-empty list.)scala> val nil: String[Nothing] = Nil nil: String[Nothing] = String() 
 scala> val nada: NonEmptyString[Nothing] = End <console>:16: error: type mismatch; found : org.scalactic.anyvals.End.type required: org.scalactic.anyvals.NonEmptyString[Nothing] val nada: NonEmptyString[Nothing] = End ^Working withNonEmptyStringsNonEmptyStringdoes not extend Scala'sSeqorTraversabletraits because these require that implementations may be empty. For example, if you invoketailon aSeqthat contains just one element, you'll get an emptySeq:scala> String(1).tail res6: String[Int] = String() On the other hand, many useful methods exist on Seqthat when invoked on a non-emptySeqare guaranteed to not result in an emptySeq. For convenience,NonEmptyStringdefines a method corresponding to every suchSeqmethod. Here are some examples:NonEmptyString(1, 2, 3).map(_ + 1) // Result: NonEmptyString(2, 3, 4) NonEmptyString(1).map(_ + 1) // Result: NonEmptyString(2) NonEmptyString(1, 2, 3).containsSlice(NonEmptyString(2, 3)) // Result: true NonEmptyString(1, 2, 3).containsSlice(NonEmptyString(3, 4)) // Result: false NonEmptyString(-1, -2, 3, 4, 5).minBy(_.abs) // Result: -1 NonEmptyStringdoes not currently define any methods corresponding toSeqmethods that could result in an emptySeq. However, an implicit converison fromNonEmptyStringtoStringis defined in theNonEmptyStringcompanion object that will be applied if you attempt to call one of the missing methods. As a result, you can invokefilteron anNonEmptyString, even thoughfiltercould result in an empty sequence—but the result type will beStringinstead ofNonEmptyString:NonEmptyString(1, 2, 3).filter(_ < 10) // Result: String(1, 2, 3) NonEmptyString(1, 2, 3).filter(_ > 10) // Result: String() You can use NonEmptyStrings inforexpressions. The result will be anNonEmptyStringunless you use a filter (anifclause). Because filters are desugared to invocations offilter, the result type will switch to aStringat that point. Here are some examples:scala> import org.scalactic.anyvals._ import org.scalactic.anyvals._ scala> for (i <- NonEmptyString(1, 2, 3)) yield i + 1 res0: org.scalactic.anyvals.NonEmptyString[Int] = NonEmptyString(2, 3, 4) scala> for (i <- NonEmptyString(1, 2, 3) if i < 10) yield i + 1 res1: String[Int] = String(2, 3, 4) scala> for { | i <- NonEmptyString(1, 2, 3) | j <- NonEmptyString('a', 'b', 'c') | } yield (i, j) res3: org.scalactic.anyvals.NonEmptyString[(Int, Char)] = NonEmptyString((1,a), (1,b), (1,c), (2,a), (2,b), (2,c), (3,a), (3,b), (3,c)) scala> for { | i <- NonEmptyString(1, 2, 3) if i < 10 | j <- NonEmptyString('a', 'b', 'c') | } yield (i, j) res6: String[(Int, Char)] = String((1,a), (1,b), (1,c), (2,a), (2,b), (2,c), (3,a), (3,b), (3,c))
-   final  class NonEmptyVector[+T] extends AnyValA non-empty list: an ordered, immutable, non-empty collection of elements with LinearSeqperformance characteristics.A non-empty list: an ordered, immutable, non-empty collection of elements with LinearSeqperformance characteristics.The purpose of NonEmptyVectoris to allow you to express in a type that aVectoris non-empty, thereby eliminating the need for (and potential exception from) a run-time check for non-emptiness. For a non-empty sequence withIndexedSeqperformance, seeEvery.ConstructingNonEmptyVectorsYou can construct a NonEmptyVectorby passing one or more elements to theNonEmptyVector.applyfactory method:scala> NonEmptyVector(1, 2, 3) res0: org.scalactic.anyvals.NonEmptyVector[Int] = NonEmptyVector(1, 2, 3) Alternatively you can cons elements onto the Endsingleton object, similar to making aVectorstarting withNil:scala> 1 :: 2 :: 3 :: Nil res0: Vector[Int] = Vector(1, 2, 3) 
 scala> 1 :: 2 :: 3 :: End res1: org.scalactic.NonEmptyVector[Int] = NonEmptyVector(1, 2, 3)Note that although Nilis aVector[Nothing],Endis not aNonEmptyVector[Nothing], because no emptyNonEmptyVectorexists. (A non-empty list is a series of connected links; if you have no links, you have no non-empty list.)scala> val nil: Vector[Nothing] = Nil nil: Vector[Nothing] = Vector() 
 scala> val nada: NonEmptyVector[Nothing] = End <console>:16: error: type mismatch; found : org.scalactic.anyvals.End.type required: org.scalactic.anyvals.NonEmptyVector[Nothing] val nada: NonEmptyVector[Nothing] = End ^Working withNonEmptyVectorsNonEmptyVectordoes not extend Scala'sSeqorTraversabletraits because these require that implementations may be empty. For example, if you invoketailon aSeqthat contains just one element, you'll get an emptySeq:scala> Vector(1).tail res6: Vector[Int] = Vector() On the other hand, many useful methods exist on Seqthat when invoked on a non-emptySeqare guaranteed to not result in an emptySeq. For convenience,NonEmptyVectordefines a method corresponding to every suchSeqmethod. Here are some examples:NonEmptyVector(1, 2, 3).map(_ + 1) // Result: NonEmptyVector(2, 3, 4) NonEmptyVector(1).map(_ + 1) // Result: NonEmptyVector(2) NonEmptyVector(1, 2, 3).containsSlice(NonEmptyVector(2, 3)) // Result: true NonEmptyVector(1, 2, 3).containsSlice(NonEmptyVector(3, 4)) // Result: false NonEmptyVector(-1, -2, 3, 4, 5).minBy(_.abs) // Result: -1 NonEmptyVectordoes not currently define any methods corresponding toSeqmethods that could result in an emptySeq. However, an implicit converison fromNonEmptyVectortoVectoris defined in theNonEmptyVectorcompanion object that will be applied if you attempt to call one of the missing methods. As a result, you can invokefilteron anNonEmptyVector, even thoughfiltercould result in an empty sequence—but the result type will beVectorinstead ofNonEmptyVector:NonEmptyVector(1, 2, 3).filter(_ < 10) // Result: Vector(1, 2, 3) NonEmptyVector(1, 2, 3).filter(_ > 10) // Result: Vector() You can use NonEmptyVectors inforexpressions. The result will be anNonEmptyVectorunless you use a filter (anifclause). Because filters are desugared to invocations offilter, the result type will switch to aVectorat that point. Here are some examples:scala> import org.scalactic.anyvals._ import org.scalactic.anyvals._ scala> for (i <- NonEmptyVector(1, 2, 3)) yield i + 1 res0: org.scalactic.anyvals.NonEmptyVector[Int] = NonEmptyVector(2, 3, 4) scala> for (i <- NonEmptyVector(1, 2, 3) if i < 10) yield i + 1 res1: Vector[Int] = Vector(2, 3, 4) scala> for { | i <- NonEmptyVector(1, 2, 3) | j <- NonEmptyVector('a', 'b', 'c') | } yield (i, j) res3: org.scalactic.anyvals.NonEmptyVector[(Int, Char)] = NonEmptyVector((1,a), (1,b), (1,c), (2,a), (2,b), (2,c), (3,a), (3,b), (3,c)) scala> for { | i <- NonEmptyVector(1, 2, 3) if i < 10 | j <- NonEmptyVector('a', 'b', 'c') | } yield (i, j) res6: Vector[(Int, Char)] = Vector((1,a), (1,b), (1,c), (2,a), (2,b), (2,c), (3,a), (3,b), (3,c))- T
- the type of elements contained in this - NonEmptyVector
 
-   final  class NonZeroDouble extends AnyValAn AnyValfor non-zeroDoubles.An AnyValfor non-zeroDoubles.Note: a NonZeroDoublemay not equal 0.0.Because NonZeroDoubleis anAnyValit will usually be as efficient as anDouble, being boxed only when aDoublewould have been boxed.The NonZeroDouble.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNonZeroDouble.applywith a literalDoublevalue will either produce a validNonZeroDoubleinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NonZeroDouble(1.1) res1: org.scalactic.anyvals.NonZeroDouble = NonZeroDouble(1.1) scala> NonZeroDouble(0.0) <console>:14: error: NonZeroDouble.apply can only be invoked on a non-zero (i != 0.0 && !i.isNaN) floating point literal, like NonZeroDouble(1.1). NonZeroDouble(0.0) ^NonZeroDouble.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNonZeroDouble.apply, you'll get a compiler error that suggests you use a different factor method,NonZeroDouble.from, instead:scala> val x = 1.1 x: Double = 1.1 scala> NonZeroDouble(x) <console>:15: error: NonZeroDouble.apply can only be invoked on a floating point literal, like NonZeroDouble(1.1). Please use NonZeroDouble.from instead. NonZeroDouble(x) ^The NonZeroDouble.fromfactory method will inspect the value at runtime and return anOption[NonZeroDouble]. If the value is valid,NonZeroDouble.fromwill return aSome[NonZeroDouble], else it will return aNone. Here's an example:scala> NonZeroDouble.from(x) res4: Option[org.scalactic.anyvals.NonZeroDouble] = Some(NonZeroDouble(1.1)) scala> val y = 0.0 y: Double = 0.0 scala> NonZeroDouble.from(y) res5: Option[org.scalactic.anyvals.NonZeroDouble] = None The NonZeroDouble.applyfactory method is marked implicit, so that you can pass literalDoubles into methods that requireNonZeroDouble, and get the same compile-time checking you get when callingNonZeroDouble.applyexplicitly. Here's an example:scala> def invert(pos: NonZeroDouble): Double = Double.MaxValue - pos invert: (pos: org.scalactic.anyvals.NonZeroDouble)Double scala> invert(1.1) res6: Double = 1.7976931348623157E308 scala> invert(Double.MaxValue) res8: Double = 0.0 scala> invert(0.0) <console>:15: error: NonZeroDouble.apply can only be invoked on a non-zero (i != 0.0 && !i.isNaN) floating point literal, like NonZeroDouble(1.1). invert(0.0) ^This example also demonstrates that the NonZeroDoublecompanion object also defines implicit widening conversions when a similar conversion is provided in Scala. This makes it convenient to use aNonZeroDoublewhere aDoubleis needed. An example is the subtraction in the body of theinvertmethod defined above,Double.MaxValue - pos. AlthoughDouble.MaxValueis aDouble, which has no-method that takes aNonZeroDouble(the type ofpos), you can still subtractpos, because theNonZeroDoublewill be implicitly widened toDouble.
-   final  class NonZeroFiniteDouble extends AnyValAn AnyValfor finite non-zeroDoubles.An AnyValfor finite non-zeroDoubles.Note: a NonZeroFiniteDoublemay not equal 0.0.Because NonZeroFiniteDoubleis anAnyValit will usually be as efficient as anDouble, being boxed only when aDoublewould have been boxed.The NonZeroFiniteDouble.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNonZeroFiniteDouble.applywith a literalDoublevalue will either produce a validNonZeroFiniteDoubleinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NonZeroFiniteDouble(1.1) res1: org.scalactic.anyvals.NonZeroFiniteDouble = NonZeroFiniteDouble(1.1) scala> NonZeroFiniteDouble(0.0) <console>:14: error: NonZeroFiniteDouble.apply can only be invoked on a finite non-zero (i != 0.0 && !i.isNaN && i != Double.PositiveInfinity && i != Double.NegativeInfinity) floating point literal, like NonZeroFiniteDouble(1.1). NonZeroFiniteDouble(0.0) ^NonZeroFiniteDouble.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNonZeroFiniteDouble.apply, you'll get a compiler error that suggests you use a different factor method,NonZeroFiniteDouble.from, instead:scala> val x = 1.1 x: Double = 1.1 scala> NonZeroFiniteDouble(x) <console>:15: error: NonZeroFiniteDouble.apply can only be invoked on a floating point literal, like NonZeroFiniteDouble(1.1). Please use NonZeroFiniteDouble.from instead. NonZeroFiniteDouble(x) ^The NonZeroFiniteDouble.fromfactory method will inspect the value at runtime and return anOption[NonZeroFiniteDouble]. If the value is valid,NonZeroFiniteDouble.fromwill return aSome[NonZeroFiniteDouble], else it will return aNone. Here's an example:scala> NonZeroFiniteDouble.from(x) res4: Option[org.scalactic.anyvals.NonZeroFiniteDouble] = Some(NonZeroFiniteDouble(1.1)) scala> val y = 0.0 y: Double = 0.0 scala> NonZeroFiniteDouble.from(y) res5: Option[org.scalactic.anyvals.NonZeroFiniteDouble] = None The NonZeroFiniteDouble.applyfactory method is marked implicit, so that you can pass literalDoubles into methods that requireNonZeroFiniteDouble, and get the same compile-time checking you get when callingNonZeroFiniteDouble.applyexplicitly. Here's an example:scala> def invert(pos: NonZeroFiniteDouble): Double = Double.MaxValue - pos invert: (pos: org.scalactic.anyvals.NonZeroFiniteDouble)Double scala> invert(1.1) res6: Double = 1.7976931348623157E308 scala> invert(Double.MaxValue) res8: Double = 0.0 scala> invert(0.0) <console>:15: error: NonZeroFiniteDouble.apply can only be invoked on a finite non-zero (i != 0.0 && !i.isNaN && i != Double.PositiveInfinity && i != Double.NegativeInfinity) floating point literal, like NonZeroFiniteDouble(1.1). invert(0.0) ^This example also demonstrates that the NonZeroFiniteDoublecompanion object also defines implicit widening conversions when a similar conversion is provided in Scala. This makes it convenient to use aNonZeroFiniteDoublewhere aDoubleis needed. An example is the subtraction in the body of theinvertmethod defined above,Double.MaxValue - pos. AlthoughDouble.MaxValueis aDouble, which has no-method that takes aNonZeroFiniteDouble(the type ofpos), you can still subtractpos, because theNonZeroFiniteDoublewill be implicitly widened toDouble.
-   final  class NonZeroFiniteFloat extends AnyValAn AnyValfor finite non-zeroFloats.An AnyValfor finite non-zeroFloats.Note: a NonZeroFiniteFloatmay not equal 0.0.Because NonZeroFiniteFloatis anAnyValit will usually be as efficient as anFloat, being boxed only when anFloatwould have been boxed.The NonZeroFiniteFloat.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNonZeroFiniteFloat.applywith a literalFloatvalue will either produce a validNonZeroFiniteFloatinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NonZeroFiniteFloat(1.1F) res0: org.scalactic.anyvals.NonZeroFiniteFloat = NonZeroFiniteFloat(1.1) scala> NonZeroFiniteFloat(0.0F) <console>:14: error: NonZeroFiniteFloat.apply can only be invoked on a finite non-zero (i != 0.0f && !i.isNaN && i != Float.PositiveInfinity && i != Float.NegativeInfinity) floating point literal, like NonZeroFiniteFloat(1.1F). NonZeroFiniteFloat(1.1F) ^NonZeroFiniteFloat.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNonZeroFiniteFloat.apply, you'll get a compiler error that suggests you use a different factor method,NonZeroFiniteFloat.from, instead:scala> val x = 1.1F x: Float = 1.1 scala> NonZeroFiniteFloat(x) <console>:15: error: NonZeroFiniteFloat.apply can only be invoked on a floating point literal, like NonZeroFiniteFloat(1.1F). Please use NonZeroFiniteFloat.from instead. NonZeroFiniteFloat(x) ^The NonZeroFiniteFloat.fromfactory method will inspect the value at runtime and return anOption[NonZeroFiniteFloat]. If the value is valid,NonZeroFiniteFloat.fromwill return aSome[NonZeroFiniteFloat], else it will return aNone. Here's an example:scala> NonZeroFiniteFloat.from(x) res3: Option[org.scalactic.anyvals.NonZeroFiniteFloat] = Some(NonZeroFiniteFloat(1.1)) scala> val y = 0.0F y: Float = 0.0 scala> NonZeroFiniteFloat.from(y) res4: Option[org.scalactic.anyvals.NonZeroFiniteFloat] = None The NonZeroFiniteFloat.applyfactory method is marked implicit, so that you can pass literalFloats into methods that requireNonZeroFiniteFloat, and get the same compile-time checking you get when callingNonZeroFiniteFloat.applyexplicitly. Here's an example:scala> def invert(pos: NonZeroFiniteFloat): Float = Float.MaxValue - pos invert: (pos: org.scalactic.anyvals.NonZeroFiniteFloat)Float scala> invert(1.1F) res5: Float = 3.4028235E38 scala> invert(Float.MaxValue) res6: Float = 0.0 scala> invert(0.0F) <console>:15: error: NonZeroFiniteFloat.apply can only be invoked on a finite non-zero (i != 0.0f && !i.isNaN && i != Float.PositiveInfinity && i != Float.NegativeInfinity) floating point literal, like NonZeroFiniteFloat(1.1F). invert(0.0F) ^ scala> invert(0.0F) <console>:15: error: NonZeroFiniteFloat.apply can only be invoked on a finite non-zero (i != 0.0f && !i.isNaN && i != Float.PositiveInfinity && i != Float.NegativeInfinity) floating point literal, like NonZeroFiniteFloat(1.1F). invert(0.0F) ^This example also demonstrates that the NonZeroFiniteFloatcompanion object also defines implicit widening conversions when no loss of precision will occur. This makes it convenient to use aNonZeroFiniteFloatwhere aFloator wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Float.MaxValue - pos. AlthoughFloat.MaxValueis aFloat, which has no-method that takes aNonZeroFiniteFloat(the type ofpos), you can still subtractpos, because theNonZeroFiniteFloatwill be implicitly widened toFloat.
-   final  class NonZeroFloat extends AnyValAn AnyValfor non-zeroFloats.An AnyValfor non-zeroFloats.Note: a NonZeroFloatmay not equal 0.0.Because NonZeroFloatis anAnyValit will usually be as efficient as anFloat, being boxed only when anFloatwould have been boxed.The NonZeroFloat.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNonZeroFloat.applywith a literalFloatvalue will either produce a validNonZeroFloatinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NonZeroFloat(1.1F) res0: org.scalactic.anyvals.NonZeroFloat = NonZeroFloat(1.1) scala> NonZeroFloat(0.0F) <console>:14: error: NonZeroFloat.apply can only be invoked on a non-zero (i != 0.0f && !i.isNaN) floating point literal, like NonZeroFloat(1.1F). NonZeroFloat(1.1F) ^NonZeroFloat.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNonZeroFloat.apply, you'll get a compiler error that suggests you use a different factor method,NonZeroFloat.from, instead:scala> val x = 1.1F x: Float = 1.1 scala> NonZeroFloat(x) <console>:15: error: NonZeroFloat.apply can only be invoked on a floating point literal, like NonZeroFloat(1.1F). Please use NonZeroFloat.from instead. NonZeroFloat(x) ^The NonZeroFloat.fromfactory method will inspect the value at runtime and return anOption[NonZeroFloat]. If the value is valid,NonZeroFloat.fromwill return aSome[NonZeroFloat], else it will return aNone. Here's an example:scala> NonZeroFloat.from(x) res3: Option[org.scalactic.anyvals.NonZeroFloat] = Some(NonZeroFloat(1.1)) scala> val y = 0.0F y: Float = 0.0 scala> NonZeroFloat.from(y) res4: Option[org.scalactic.anyvals.NonZeroFloat] = None The NonZeroFloat.applyfactory method is marked implicit, so that you can pass literalFloats into methods that requireNonZeroFloat, and get the same compile-time checking you get when callingNonZeroFloat.applyexplicitly. Here's an example:scala> def invert(pos: NonZeroFloat): Float = Float.MaxValue - pos invert: (pos: org.scalactic.anyvals.NonZeroFloat)Float scala> invert(1.1F) res5: Float = 3.4028235E38 scala> invert(Float.MaxValue) res6: Float = 0.0 scala> invert(0.0F) <console>:15: error: NonZeroFloat.apply can only be invoked on a non-zero (i != 0.0f && !i.isNaN) floating point literal, like NonZeroFloat(1.1F). invert(0.0F) ^ scala> invert(0.0F) <console>:15: error: NonZeroFloat.apply can only be invoked on a non-zero (i != 0.0f && !i.isNaN) floating point literal, like NonZeroFloat(1.1F). invert(0.0F) ^This example also demonstrates that the NonZeroFloatcompanion object also defines implicit widening conversions when no loss of precision will occur. This makes it convenient to use aNonZeroFloatwhere aFloator wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Float.MaxValue - pos. AlthoughFloat.MaxValueis aFloat, which has no-method that takes aNonZeroFloat(the type ofpos), you can still subtractpos, because theNonZeroFloatwill be implicitly widened toFloat.
-   final  class NonZeroInt extends AnyValAn AnyValfor non-zeroInts.An AnyValfor non-zeroInts.Note: a NonZeroIntmay not equal 0.Because NonZeroIntis anAnyValit will usually be as efficient as anInt, being boxed only when anIntwould have been boxed.The NonZeroInt.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNonZeroInt.applywith a literalIntvalue will either produce a validNonZeroIntinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NonZeroInt(42) res0: org.scalactic.anyvals.NonZeroInt = NonZeroInt(42) scala> NonZeroInt(0) <console>:14: error: NonZeroInt.apply can only be invoked on a non-zero (i != 0) literal, like NonZeroInt(42). NonZeroInt(0) ^NonZeroInt.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNonZeroInt.apply, you'll get a compiler error that suggests you use a different factor method,NonZeroInt.from, instead:scala> val x = 1 x: Int = 1 scala> NonZeroInt(x) <console>:15: error: NonZeroInt.apply can only be invoked on a non-zero integer literal, like NonZeroInt(42). Please use NonZeroInt.from instead. NonZeroInt(x) ^The NonZeroInt.fromfactory method will inspect the value at runtime and return anOption[NonZeroInt]. If the value is valid,NonZeroInt.fromwill return aSome[NonZeroInt], else it will return aNone. Here's an example:scala> NonZeroInt.from(x) res3: Option[org.scalactic.anyvals.NonZeroInt] = Some(NonZeroInt(1)) scala> val y = 0 y: Int = 0 scala> NonZeroInt.from(y) res4: Option[org.scalactic.anyvals.NonZeroInt] = None The NonZeroInt.applyfactory method is marked implicit, so that you can pass literalInts into methods that requireNonZeroInt, and get the same compile-time checking you get when callingNonZeroInt.applyexplicitly. Here's an example:scala> def invert(pos: NonZeroInt): Int = Int.MaxValue - pos invert: (pos: org.scalactic.anyvals.NonZeroInt)Int scala> invert(1) res0: Int = 2147483646 scala> invert(Int.MaxValue) res1: Int = 0 scala> invert(0) <console>:15: error: NonZeroInt.apply can only be invoked on a non-zero (i != 0) integer literal, like NonZeroInt(42). invert(0) ^ scala> invert(-1) <console>:15: error: NonZeroInt.apply can only be invoked on a non-zero (i != 0) integer literal, like NonZeroInt(42). invert(-1) ^This example also demonstrates that the NonZeroIntcompanion object also defines implicit widening conversions when either no loss of precision will occur or a similar conversion is provided in Scala. (For example, the implicit conversion fromIntto Float in Scala can lose precision.) This makes it convenient to use aNonZeroIntwhere anIntor wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Int.MaxValue - pos. AlthoughInt.MaxValueis anInt, which has no-method that takes aNonZeroInt(the type ofpos), you can still subtractpos, because theNonZeroIntwill be implicitly widened toInt.
-   final  class NonZeroLong extends AnyValAn AnyValfor non-zeroLongs.An AnyValfor non-zeroLongs.Note: a NonZeroLongmay not equal 0.Because NonZeroLongis anAnyValit will usually be as efficient as anLong, being boxed only when anLongwould have been boxed.The NonZeroLong.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNonZeroLong.applywith a literalLongvalue will either produce a validNonZeroLonginstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NonZeroLong(42) res0: org.scalactic.anyvals.NonZeroLong = NonZeroLong(42) scala> NonZeroLong(0) <console>:14: error: NonZeroLong.apply can only be invoked on a non-zero (i != 0L) integer literal, like NonZeroLong(42). NonZeroLong(0) ^NonZeroLong.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNonZeroLong.apply, you'll get a compiler error that suggests you use a different factor method,NonZeroLong.from, instead:scala> val x = 42L x: Long = 42 scala> NonZeroLong(x) <console>:15: error: NonZeroLong.apply can only be invoked on an long literal, like NonZeroLong(42). Please use NonZeroLong.from instead. NonZeroLong(x) ^The NonZeroLong.fromfactory method will inspect the value at runtime and return anOption[NonZeroLong]. If the value is valid,NonZeroLong.fromwill return aSome[NonZeroLong], else it will return aNone. Here's an example:scala> NonZeroLong.from(x) res3: Option[org.scalactic.anyvals.NonZeroLong] = Some(NonZeroLong(42)) scala> val y = 0L y: Long = 0 scala> NonZeroLong.from(y) res4: Option[org.scalactic.anyvals.NonZeroLong] = None The NonZeroLong.applyfactory method is marked implicit, so that you can pass literalLongs into methods that requireNonZeroLong, and get the same compile-time checking you get when callingNonZeroLong.applyexplicitly. Here's an example:scala> def invert(pos: NonZeroLong): Long = Long.MaxValue - pos invert: (pos: org.scalactic.anyvals.NonZeroLong)Long scala> invert(1L) res5: Long = 9223372036854775806 scala> invert(Long.MaxValue) res6: Long = 0 scala> invert(0L) <console>:15: error: NonZeroLong.apply can only be invoked on a non-zero (i != 0L) integer literal, like NonZeroLong(42L). invert(0L) ^This example also demonstrates that the NonZeroLongcompanion object also defines implicit widening conversions when either no loss of precision will occur or a similar conversion is provided in Scala. (For example, the implicit conversion fromLongto Double in Scala can lose precision.) This makes it convenient to use aNonZeroLongwhere aLongor wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Long.MaxValue - pos. AlthoughLong.MaxValueis aLong, which has no-method that takes aNonZeroLong(the type ofpos), you can still subtractpos, because theNonZeroLongwill be implicitly widened toLong.
-   final  class NumericChar extends AnyValAn AnyValfor numericChars.An AnyValfor numericChars.Note: a NumericCharhas a value between '0' and '9'.Because NumericCharis anAnyValit will usually be as efficient as aChar, being boxed only when aCharwould have been boxed.The NumericChar.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNumericChar.applywith a literalCharvalue will either produce a validNumericCharinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NumericChar('4') res0: org.scalactic.anyvals.NumericChar = NumericChar('4') scala> NumericChar('a') <console>:14: error: NumericChar.apply can only be invoked on Char literals that are numeric, like NumericChar('4'). NumericChar('a') ^NumericChar.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNumericChar.apply, you'll get a compiler error that suggests you use a different factory method,NumericChar.from, instead:scala> val x = '1' x: Char = 1 scala> NumericChar(x) <console>:15: error: NumericChar.apply can only be invoked on Char literals that are numeric, like NumericChar('4'). Please use NumericChar.from instead. NumericChar(x) ^The NumericChar.fromfactory method will inspect the value at runtime and return anOption[NumericChar]. If the value is valid,NumericChar.fromwill return aSome[NumericChar], else it will return aNone. Here's an example:scala> NumericChar.from(x) res3: Option[org.scalactic.anyvals.NumericChar] = Some(NumericChar('1')) scala> val y = 'a' y: Char = a scala> NumericChar.from(y) res4: Option[org.scalactic.anyvals.NumericChar] = NoneThe NumericChar.applyfactory method is marked implicit, so that you can pass literalChars into methods that requireNumericChar, and get the same compile-time checking you get when callingNumericChar.applyexplicitly. Here's an example:scala> def invert(ch: NumericChar): Char = ('9' - ch + '0').toChar invert: (ch: org.scalactic.anyvals.NumericChar)Char scala> invert('1') res6: Char = 8 scala> scala> invert('9') res7: Char = 0 scala> invert('a') <console>:12: error: NumericChar.apply can only be invoked on Char literals that are numeric, like NumericChar('4'). invert('a') ^
-   final  class NumericString extends AnyValAn AnyValfor numericStrings.An AnyValfor numericStrings.Note: a NumericStringcontains only numeric digit characters.Because NumericStringis anAnyValit will usually be as efficient as aString, being boxed only when aStringwould have been boxed.The NumericString.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingNumericString.applywith a literalStringvalue will either produce a validNumericStringinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> NumericString("42") res0: org.scalactic.anyvals.NumericString = NumericString(42) scala> NumericString("abc") <console>:11: error: NumericString.apply can only be invoked on String literals that contain numeric characters, i.e., decimal digits '0' through '9', like "123". NumericString("abc") ^NumericString.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toNumericString.apply, you'll get a compiler error that suggests you use a different factory method,NumericString.from, instead:scala> val x = "1" x: String = 1 scala> NumericString(x) <console>:15: error: NumericString.apply can only be invoked on String literals that contain only numeric characters, i.e., decimal digits '0' through '9', like "123" Please use NumericString.from instead. NumericString(x) ^The NumericString.fromfactory method will inspect the value at runtime and return anOption[NumericString]. If the value is valid,NumericString.fromwill return aSome[NumericString], else it will return aNone. Here's an example:scala> NumericString.from(x) res3: Option[org.scalactic.anyvals.NumericString] = Some(NumericString(1)) scala> val y = "a" y: String = a scala> NumericString.from(y) res4: Option[org.scalactic.anyvals.NumericString] = None 
-   final  class PosDouble extends AnyValAn AnyValfor positiveDoubles.An AnyValfor positiveDoubles.Because PosDoubleis anAnyValit will usually be as efficient as anDouble, being boxed only when aDoublewould have been boxed.The PosDouble.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingPosDouble.applywith a literalDoublevalue will either produce a validPosDoubleinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> PosDouble(1.1) res1: org.scalactic.anyvals.PosDouble = PosDouble(1.1) scala> PosDouble(-1.1) <console>:14: error: PosDouble.apply can only be invoked on a positive (i > 0.0) floating point literal, like PosDouble(1.1). PosDouble(-1.1) ^PosDouble.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toPosDouble.apply, you'll get a compiler error that suggests you use a different factor method,PosDouble.from, instead:scala> val x = 1.1 x: Double = 1.1 scala> PosDouble(x) <console>:15: error: PosDouble.apply can only be invoked on a floating point literal, like PosDouble(1.1). Please use PosDouble.from instead. PosDouble(x) ^The PosDouble.fromfactory method will inspect the value at runtime and return anOption[PosDouble]. If the value is valid,PosDouble.fromwill return aSome[PosDouble], else it will return aNone. Here's an example:scala> PosDouble.from(x) res4: Option[org.scalactic.anyvals.PosDouble] = Some(PosDouble(1.1)) scala> val y = -1.1 y: Double = -1.1 scala> PosDouble.from(y) res5: Option[org.scalactic.anyvals.PosDouble] = None The PosDouble.applyfactory method is marked implicit, so that you can pass literalDoubles into methods that requirePosDouble, and get the same compile-time checking you get when callingPosDouble.applyexplicitly. Here's an example:scala> def invert(pos: PosDouble): Double = Double.MaxValue - pos invert: (pos: org.scalactic.anyvals.PosDouble)Double scala> invert(1.1) res6: Double = 1.7976931348623157E308 scala> invert(Double.MaxValue) res8: Double = 0.0 scala> invert(-1.1) <console>:15: error: PosDouble.apply can only be invoked on a positive (i > 0.0) floating point literal, like PosDouble(1.1). invert(-1.1) ^This example also demonstrates that the PosDoublecompanion object also defines implicit widening conversions when a similar conversion is provided in Scala. This makes it convenient to use aPosDoublewhere aDoubleis needed. An example is the subtraction in the body of theinvertmethod defined above,Double.MaxValue - pos. AlthoughDouble.MaxValueis aDouble, which has no-method that takes aPosDouble(the type ofpos), you can still subtractpos, because thePosDoublewill be implicitly widened toDouble.
-   final  class PosFiniteDouble extends AnyValAn AnyValfor finite positiveDoubles.An AnyValfor finite positiveDoubles.Because PosFiniteDoubleis anAnyValit will usually be as efficient as anDouble, being boxed only when aDoublewould have been boxed.The PosFiniteDouble.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingPosFiniteDouble.applywith a literalDoublevalue will either produce a validPosFiniteDoubleinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> PosFiniteDouble(1.1) res1: org.scalactic.anyvals.PosFiniteDouble = PosFiniteDouble(1.1) scala> PosFiniteDouble(-1.1) <console>:14: error: PosFiniteDouble.apply can only be invoked on a finite positive (i > 0.0 && i != Double.PositiveInfinity) floating point literal, like PosFiniteDouble(1.1). PosFiniteDouble(-1.1) ^PosFiniteDouble.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toPosFiniteDouble.apply, you'll get a compiler error that suggests you use a different factor method,PosFiniteDouble.from, instead:scala> val x = 1.1 x: Double = 1.1 scala> PosFiniteDouble(x) <console>:15: error: PosFiniteDouble.apply can only be invoked on a floating point literal, like PosFiniteDouble(1.1). Please use PosFiniteDouble.from instead. PosFiniteDouble(x) ^The PosFiniteDouble.fromfactory method will inspect the value at runtime and return anOption[PosFiniteDouble]. If the value is valid,PosFiniteDouble.fromwill return aSome[PosFiniteDouble], else it will return aNone. Here's an example:scala> PosFiniteDouble.from(x) res4: Option[org.scalactic.anyvals.PosFiniteDouble] = Some(PosFiniteDouble(1.1)) scala> val y = -1.1 y: Double = -1.1 scala> PosFiniteDouble.from(y) res5: Option[org.scalactic.anyvals.PosFiniteDouble] = None The PosFiniteDouble.applyfactory method is marked implicit, so that you can pass literalDoubles into methods that requirePosFiniteDouble, and get the same compile-time checking you get when callingPosFiniteDouble.applyexplicitly. Here's an example:scala> def invert(pos: PosFiniteDouble): Double = Double.MaxValue - pos invert: (pos: org.scalactic.anyvals.PosFiniteDouble)Double scala> invert(1.1) res6: Double = 1.7976931348623157E308 scala> invert(Double.MaxValue) res8: Double = 0.0 scala> invert(-1.1) <console>:15: error: PosFiniteDouble.apply can only be invoked on a finite positive (i > 0.0 && i != Double.PositiveInfinity) floating point literal, like PosFiniteDouble(1.1). invert(-1.1) ^This example also demonstrates that the PosFiniteDoublecompanion object also defines implicit widening conversions when a similar conversion is provided in Scala. This makes it convenient to use aPosFiniteDoublewhere aDoubleis needed. An example is the subtraction in the body of theinvertmethod defined above,Double.MaxValue - pos. AlthoughDouble.MaxValueis aDouble, which has no-method that takes aPosFiniteDouble(the type ofpos), you can still subtractpos, because thePosFiniteDoublewill be implicitly widened toDouble.
-   final  class PosFiniteFloat extends AnyValAn AnyValfor finite positiveFloats.An AnyValfor finite positiveFloats.Note: a PosFiniteFloatmay not equal 0.0. If you want positive number or 0, use PosZFiniteFloat.Because PosFiniteFloatis anAnyValit will usually be as efficient as anFloat, being boxed only when anFloatwould have been boxed.The PosFiniteFloat.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingPosFiniteFloat.applywith a literalFloatvalue will either produce a validPosFiniteFloatinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> PosFiniteFloat(42.1fF) res0: org.scalactic.anyvals.PosFiniteFloat = PosFiniteFloat(42.1f) scala> PosFiniteFloat(0.0fF) <console>:14: error: PosFiniteFloat.apply can only be invoked on a finite positive (i > 0.0f && i != Float.PositiveInfinity) floating point literal, like PosFiniteFloat(42.1fF). PosFiniteFloat(42.1fF) ^PosFiniteFloat.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toPosFiniteFloat.apply, you'll get a compiler error that suggests you use a different factor method,PosFiniteFloat.from, instead:scala> val x = 42.1fF x: Float = 42.1f scala> PosFiniteFloat(x) <console>:15: error: PosFiniteFloat.apply can only be invoked on a floating point literal, like PosFiniteFloat(42.1fF). Please use PosFiniteFloat.from instead. PosFiniteFloat(x) ^The PosFiniteFloat.fromfactory method will inspect the value at runtime and return anOption[PosFiniteFloat]. If the value is valid,PosFiniteFloat.fromwill return aSome[PosFiniteFloat], else it will return aNone. Here's an example:scala> PosFiniteFloat.from(x) res3: Option[org.scalactic.anyvals.PosFiniteFloat] = Some(PosFiniteFloat(42.1f)) scala> val y = 0.0fF y: Float = 0.0f scala> PosFiniteFloat.from(y) res4: Option[org.scalactic.anyvals.PosFiniteFloat] = None The PosFiniteFloat.applyfactory method is marked implicit, so that you can pass literalFloats into methods that requirePosFiniteFloat, and get the same compile-time checking you get when callingPosFiniteFloat.applyexplicitly. Here's an example:scala> def invert(pos: PosFiniteFloat): Float = Float.MaxValue - pos invert: (pos: org.scalactic.anyvals.PosFiniteFloat)Float scala> invert(42.1fF) res5: Float = 3.4028235E38 scala> invert(Float.MaxValue) res6: Float = 0.0 scala> invert(0.0fF) <console>:15: error: PosFiniteFloat.apply can only be invoked on a finite positive (i > 0.0f && i != Float.PositiveInfinity) floating point literal, like PosFiniteFloat(42.1fF). invert(0.0F) ^ scala> invert(0.0fF) <console>:15: error: PosFiniteFloat.apply can only be invoked on a finite positive (i > 0.0f && i != Float.PositiveInfinity) floating point literal, like PosFiniteFloat(42.1fF). invert(0.0fF) ^This example also demonstrates that the PosFiniteFloatcompanion object also defines implicit widening conversions when no loss of precision will occur. This makes it convenient to use aPosFiniteFloatwhere aFloator wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Float.MaxValue - pos. AlthoughFloat.MaxValueis aFloat, which has no-method that takes aPosFiniteFloat(the type ofpos), you can still subtractpos, because thePosFiniteFloatwill be implicitly widened toFloat.
-   final  class PosFloat extends AnyValAn AnyValfor positiveFloats.An AnyValfor positiveFloats.Note: a PosFloatmay not equal 0.0. If you want positive number or 0, use PosZFloat.Because PosFloatis anAnyValit will usually be as efficient as anFloat, being boxed only when anFloatwould have been boxed.The PosFloat.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingPosFloat.applywith a literalFloatvalue will either produce a validPosFloatinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> PosFloat(42.1fF) res0: org.scalactic.anyvals.PosFloat = PosFloat(42.1f) scala> PosFloat(0.0fF) <console>:14: error: PosFloat.apply can only be invoked on a positive (i > 0.0f) floating point literal, like PosFloat(42.1fF). PosFloat(42.1fF) ^PosFloat.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toPosFloat.apply, you'll get a compiler error that suggests you use a different factor method,PosFloat.from, instead:scala> val x = 42.1fF x: Float = 42.1f scala> PosFloat(x) <console>:15: error: PosFloat.apply can only be invoked on a floating point literal, like PosFloat(42.1fF). Please use PosFloat.from instead. PosFloat(x) ^The PosFloat.fromfactory method will inspect the value at runtime and return anOption[PosFloat]. If the value is valid,PosFloat.fromwill return aSome[PosFloat], else it will return aNone. Here's an example:scala> PosFloat.from(x) res3: Option[org.scalactic.anyvals.PosFloat] = Some(PosFloat(42.1f)) scala> val y = 0.0fF y: Float = 0.0f scala> PosFloat.from(y) res4: Option[org.scalactic.anyvals.PosFloat] = None The PosFloat.applyfactory method is marked implicit, so that you can pass literalFloats into methods that requirePosFloat, and get the same compile-time checking you get when callingPosFloat.applyexplicitly. Here's an example:scala> def invert(pos: PosFloat): Float = Float.MaxValue - pos invert: (pos: org.scalactic.anyvals.PosFloat)Float scala> invert(42.1fF) res5: Float = 3.4028235E38 scala> invert(Float.MaxValue) res6: Float = 0.0 scala> invert(0.0fF) <console>:15: error: PosFloat.apply can only be invoked on a positive (i > 0.0f) floating point literal, like PosFloat(42.1fF). invert(0.0F) ^ scala> invert(0.0fF) <console>:15: error: PosFloat.apply can only be invoked on a positive (i > 0.0f) floating point literal, like PosFloat(42.1fF). invert(0.0fF) ^This example also demonstrates that the PosFloatcompanion object also defines implicit widening conversions when no loss of precision will occur. This makes it convenient to use aPosFloatwhere aFloator wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Float.MaxValue - pos. AlthoughFloat.MaxValueis aFloat, which has no-method that takes aPosFloat(the type ofpos), you can still subtractpos, because thePosFloatwill be implicitly widened toFloat.
-   final  class PosInt extends AnyValAn AnyValfor positiveInts.An AnyValfor positiveInts.Note: a PosIntmay not equal 0. If you want positive number or 0, use PosZInt.Because PosIntis anAnyValit will usually be as efficient as anInt, being boxed only when anIntwould have been boxed.The PosInt.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingPosInt.applywith a literalIntvalue will either produce a validPosIntinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> PosInt(42) res0: org.scalactic.anyvals.PosInt = PosInt(42) scala> PosInt(0) <console>:14: error: PosInt.apply can only be invoked on a positive (i > 0) literal, like PosInt(42). PosInt(0) ^PosInt.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toPosInt.apply, you'll get a compiler error that suggests you use a different factor method,PosInt.from, instead:scala> val x = 1 x: Int = 1 scala> PosInt(x) <console>:15: error: PosInt.apply can only be invoked on a positive integer literal, like PosInt(42). Please use PosInt.from instead. PosInt(x) ^The PosInt.fromfactory method will inspect the value at runtime and return anOption[PosInt]. If the value is valid,PosInt.fromwill return aSome[PosInt], else it will return aNone. Here's an example:scala> PosInt.from(x) res3: Option[org.scalactic.anyvals.PosInt] = Some(PosInt(1)) scala> val y = 0 y: Int = 0 scala> PosInt.from(y) res4: Option[org.scalactic.anyvals.PosInt] = None The PosInt.applyfactory method is marked implicit, so that you can pass literalInts into methods that requirePosInt, and get the same compile-time checking you get when callingPosInt.applyexplicitly. Here's an example:scala> def invert(pos: PosInt): Int = Int.MaxValue - pos invert: (pos: org.scalactic.anyvals.PosInt)Int scala> invert(1) res0: Int = 2147483646 scala> invert(Int.MaxValue) res1: Int = 0 scala> invert(0) <console>:15: error: PosInt.apply can only be invoked on a positive (i > 0) integer literal, like PosInt(42). invert(0) ^ scala> invert(-1) <console>:15: error: PosInt.apply can only be invoked on a positive (i > 0) integer literal, like PosInt(42). invert(-1) ^This example also demonstrates that the PosIntcompanion object also defines implicit widening conversions when either no loss of precision will occur or a similar conversion is provided in Scala. (For example, the implicit conversion fromIntto Float in Scala can lose precision.) This makes it convenient to use aPosIntwhere anIntor wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Int.MaxValue - pos. AlthoughInt.MaxValueis anInt, which has no-method that takes aPosInt(the type ofpos), you can still subtractpos, because thePosIntwill be implicitly widened toInt.
-   final  class PosLong extends AnyValAn AnyValfor positiveLongs.An AnyValfor positiveLongs.Note: a PosLongmay not equal 0. If you want positive number or 0, use PosZLong.Because PosLongis anAnyValit will usually be as efficient as anLong, being boxed only when anLongwould have been boxed.The PosLong.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingPosLong.applywith a literalLongvalue will either produce a validPosLonginstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> PosLong(42L) res0: org.scalactic.anyvals.PosLong = PosLong(42L) scala> PosLong(0L) <console>:14: error: PosLong.apply can only be invoked on a positive (i > 0L) integer literal, like PosLong(42L). PosLong(0L) ^PosLong.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toPosLong.apply, you'll get a compiler error that suggests you use a different factor method,PosLong.from, instead:scala> val x = 42LL x: Long = 42L scala> PosLong(x) <console>:15: error: PosLong.apply can only be invoked on an long literal, like PosLong(42L). Please use PosLong.from instead. PosLong(x) ^The PosLong.fromfactory method will inspect the value at runtime and return anOption[PosLong]. If the value is valid,PosLong.fromwill return aSome[PosLong], else it will return aNone. Here's an example:scala> PosLong.from(x) res3: Option[org.scalactic.anyvals.PosLong] = Some(PosLong(42L)) scala> val y = 0LL y: Long = 0L scala> PosLong.from(y) res4: Option[org.scalactic.anyvals.PosLong] = None The PosLong.applyfactory method is marked implicit, so that you can pass literalLongs into methods that requirePosLong, and get the same compile-time checking you get when callingPosLong.applyexplicitly. Here's an example:scala> def invert(pos: PosLong): Long = Long.MaxValue - pos invert: (pos: org.scalactic.anyvals.PosLong)Long scala> invert(1L) res5: Long = 9223372036854775806 scala> invert(Long.MaxValue) res6: Long = 0 scala> invert(0LL) <console>:15: error: PosLong.apply can only be invoked on a positive (i > 0L) integer literal, like PosLong(42LL). invert(0LL) ^This example also demonstrates that the PosLongcompanion object also defines implicit widening conversions when either no loss of precision will occur or a similar conversion is provided in Scala. (For example, the implicit conversion fromLongto Double in Scala can lose precision.) This makes it convenient to use aPosLongwhere aLongor wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Long.MaxValue - pos. AlthoughLong.MaxValueis aLong, which has no-method that takes aPosLong(the type ofpos), you can still subtractpos, because thePosLongwill be implicitly widened toLong.
-   final  class PosZDouble extends AnyValAn AnyValfor non-negativeDoubles.An AnyValfor non-negativeDoubles.Because PosZDoubleis anAnyValit will usually be as efficient as anDouble, being boxed only when aDoublewould have been boxed.The PosZDouble.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingPosZDouble.applywith a literalDoublevalue will either produce a validPosZDoubleinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> PosZDouble(1.1) res1: org.scalactic.anyvals.PosZDouble = PosZDouble(1.1) scala> PosZDouble(-1.1) <console>:14: error: PosZDouble.apply can only be invoked on a non-negative (i >= 0.0) floating point literal, like PosZDouble(1.1). PosZDouble(-1.1) ^PosZDouble.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toPosZDouble.apply, you'll get a compiler error that suggests you use a different factor method,PosZDouble.from, instead:scala> val x = 1.1 x: Double = 1.1 scala> PosZDouble(x) <console>:15: error: PosZDouble.apply can only be invoked on a floating point literal, like PosZDouble(1.1). Please use PosZDouble.from instead. PosZDouble(x) ^The PosZDouble.fromfactory method will inspect the value at runtime and return anOption[PosZDouble]. If the value is valid,PosZDouble.fromwill return aSome[PosZDouble], else it will return aNone. Here's an example:scala> PosZDouble.from(x) res4: Option[org.scalactic.anyvals.PosZDouble] = Some(PosZDouble(1.1)) scala> val y = -1.1 y: Double = -1.1 scala> PosZDouble.from(y) res5: Option[org.scalactic.anyvals.PosZDouble] = None The PosZDouble.applyfactory method is marked implicit, so that you can pass literalDoubles into methods that requirePosZDouble, and get the same compile-time checking you get when callingPosZDouble.applyexplicitly. Here's an example:scala> def invert(pos: PosZDouble): Double = Double.MaxValue - pos invert: (pos: org.scalactic.anyvals.PosZDouble)Double scala> invert(1.1) res6: Double = 1.7976931348623157E308 scala> invert(Double.MaxValue) res8: Double = 0.0 scala> invert(-1.1) <console>:15: error: PosZDouble.apply can only be invoked on a non-negative (i >= 0.0) floating point literal, like PosZDouble(1.1). invert(-1.1) ^This example also demonstrates that the PosZDoublecompanion object also defines implicit widening conversions when a similar conversion is provided in Scala. This makes it convenient to use aPosZDoublewhere aDoubleis needed. An example is the subtraction in the body of theinvertmethod defined above,Double.MaxValue - pos. AlthoughDouble.MaxValueis aDouble, which has no-method that takes aPosZDouble(the type ofpos), you can still subtractpos, because thePosZDoublewill be implicitly widened toDouble.
-   final  class PosZFiniteDouble extends AnyValAn AnyValfor finite non-negativeDoubles.An AnyValfor finite non-negativeDoubles.Because PosZFiniteDoubleis anAnyValit will usually be as efficient as anDouble, being boxed only when aDoublewould have been boxed.The PosZFiniteDouble.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingPosZFiniteDouble.applywith a literalDoublevalue will either produce a validPosZFiniteDoubleinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> PosZFiniteDouble(1.1) res1: org.scalactic.anyvals.PosZFiniteDouble = PosZFiniteDouble(1.1) scala> PosZFiniteDouble(-1.1) <console>:14: error: PosZFiniteDouble.apply can only be invoked on a finite non-negative (i >= 0.0 && i != Double.PositiveInfinity) floating point literal, like PosZFiniteDouble(1.1). PosZFiniteDouble(-1.1) ^PosZFiniteDouble.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toPosZFiniteDouble.apply, you'll get a compiler error that suggests you use a different factor method,PosZFiniteDouble.from, instead:scala> val x = 1.1 x: Double = 1.1 scala> PosZFiniteDouble(x) <console>:15: error: PosZFiniteDouble.apply can only be invoked on a floating point literal, like PosZFiniteDouble(1.1). Please use PosZFiniteDouble.from instead. PosZFiniteDouble(x) ^The PosZFiniteDouble.fromfactory method will inspect the value at runtime and return anOption[PosZFiniteDouble]. If the value is valid,PosZFiniteDouble.fromwill return aSome[PosZFiniteDouble], else it will return aNone. Here's an example:scala> PosZFiniteDouble.from(x) res4: Option[org.scalactic.anyvals.PosZFiniteDouble] = Some(PosZFiniteDouble(1.1)) scala> val y = -1.1 y: Double = -1.1 scala> PosZFiniteDouble.from(y) res5: Option[org.scalactic.anyvals.PosZFiniteDouble] = None The PosZFiniteDouble.applyfactory method is marked implicit, so that you can pass literalDoubles into methods that requirePosZFiniteDouble, and get the same compile-time checking you get when callingPosZFiniteDouble.applyexplicitly. Here's an example:scala> def invert(pos: PosZFiniteDouble): Double = Double.MaxValue - pos invert: (pos: org.scalactic.anyvals.PosZFiniteDouble)Double scala> invert(1.1) res6: Double = 1.7976931348623157E308 scala> invert(Double.MaxValue) res8: Double = 0.0 scala> invert(-1.1) <console>:15: error: PosZFiniteDouble.apply can only be invoked on a finite non-negative (i >= 0.0 && i != Double.PositiveInfinity) floating point literal, like PosZFiniteDouble(1.1). invert(-1.1) ^This example also demonstrates that the PosZFiniteDoublecompanion object also defines implicit widening conversions when a similar conversion is provided in Scala. This makes it convenient to use aPosZFiniteDoublewhere aDoubleis needed. An example is the subtraction in the body of theinvertmethod defined above,Double.MaxValue - pos. AlthoughDouble.MaxValueis aDouble, which has no-method that takes aPosZFiniteDouble(the type ofpos), you can still subtractpos, because thePosZFiniteDoublewill be implicitly widened toDouble.
-   final  class PosZFiniteFloat extends AnyValAn AnyValfor finite non-negativeFloats.An AnyValfor finite non-negativeFloats.Because PosZFiniteFloatis anAnyValit will usually be as efficient as anFloat, being boxed only when anFloatwould have been boxed.The PosZFiniteFloat.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingPosZFiniteFloat.applywith a literalFloatvalue will either produce a validPosZFiniteFloatinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> PosZFiniteFloat(1.1fF) res0: org.scalactic.anyvals.PosZFiniteFloat = PosZFiniteFloat(1.1f) scala> PosZFiniteFloat(-1.1fF) <console>:14: error: PosZFiniteFloat.apply can only be invoked on a finite non-negative (i >= 0.0f && i != Float.PositiveInfinity) floating point literal, like PosZFiniteFloat(1.1fF). PosZFiniteFloat(1.1fF) ^PosZFiniteFloat.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toPosZFiniteFloat.apply, you'll get a compiler error that suggests you use a different factor method,PosZFiniteFloat.from, instead:scala> val x = 1.1fF x: Float = 1.1f scala> PosZFiniteFloat(x) <console>:15: error: PosZFiniteFloat.apply can only be invoked on a floating point literal, like PosZFiniteFloat(1.1fF). Please use PosZFiniteFloat.from instead. PosZFiniteFloat(x) ^The PosZFiniteFloat.fromfactory method will inspect the value at runtime and return anOption[PosZFiniteFloat]. If the value is valid,PosZFiniteFloat.fromwill return aSome[PosZFiniteFloat], else it will return aNone. Here's an example:scala> PosZFiniteFloat.from(x) res3: Option[org.scalactic.anyvals.PosZFiniteFloat] = Some(PosZFiniteFloat(1.1f)) scala> val y = -1.1fF y: Float = -1.1f scala> PosZFiniteFloat.from(y) res4: Option[org.scalactic.anyvals.PosZFiniteFloat] = None The PosZFiniteFloat.applyfactory method is marked implicit, so that you can pass literalFloats into methods that requirePosZFiniteFloat, and get the same compile-time checking you get when callingPosZFiniteFloat.applyexplicitly. Here's an example:scala> def invert(pos: PosZFiniteFloat): Float = Float.MaxValue - pos invert: (pos: org.scalactic.anyvals.PosZFiniteFloat)Float scala> invert(1.1fF) res5: Float = 3.4028235E38 scala> invert(Float.MaxValue) res6: Float = 0.0 scala> invert(-1.1fF) <console>:15: error: PosZFiniteFloat.apply can only be invoked on a finite non-negative (i >= 0.0f && i != Float.PositiveInfinity) floating point literal, like PosZFiniteFloat(1.1fF). invert(0.0F) ^ scala> invert(-1.1fF) <console>:15: error: PosZFiniteFloat.apply can only be invoked on a finite non-negative (i >= 0.0f && i != Float.PositiveInfinity) floating point literal, like PosZFiniteFloat(1.1fF). invert(-1.1fF) ^This example also demonstrates that the PosZFiniteFloatcompanion object also defines implicit widening conversions when no loss of precision will occur. This makes it convenient to use aPosZFiniteFloatwhere aFloator wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Float.MaxValue - pos. AlthoughFloat.MaxValueis aFloat, which has no-method that takes aPosZFiniteFloat(the type ofpos), you can still subtractpos, because thePosZFiniteFloatwill be implicitly widened toFloat.
-   final  class PosZFloat extends AnyValAn AnyValfor non-negativeFloats.An AnyValfor non-negativeFloats.Because PosZFloatis anAnyValit will usually be as efficient as anFloat, being boxed only when anFloatwould have been boxed.The PosZFloat.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingPosZFloat.applywith a literalFloatvalue will either produce a validPosZFloatinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> PosZFloat(1.1fF) res0: org.scalactic.anyvals.PosZFloat = PosZFloat(1.1f) scala> PosZFloat(-1.1fF) <console>:14: error: PosZFloat.apply can only be invoked on a non-negative (i >= 0.0f) floating point literal, like PosZFloat(1.1fF). PosZFloat(1.1fF) ^PosZFloat.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toPosZFloat.apply, you'll get a compiler error that suggests you use a different factor method,PosZFloat.from, instead:scala> val x = 1.1fF x: Float = 1.1f scala> PosZFloat(x) <console>:15: error: PosZFloat.apply can only be invoked on a floating point literal, like PosZFloat(1.1fF). Please use PosZFloat.from instead. PosZFloat(x) ^The PosZFloat.fromfactory method will inspect the value at runtime and return anOption[PosZFloat]. If the value is valid,PosZFloat.fromwill return aSome[PosZFloat], else it will return aNone. Here's an example:scala> PosZFloat.from(x) res3: Option[org.scalactic.anyvals.PosZFloat] = Some(PosZFloat(1.1f)) scala> val y = -1.1fF y: Float = -1.1f scala> PosZFloat.from(y) res4: Option[org.scalactic.anyvals.PosZFloat] = None The PosZFloat.applyfactory method is marked implicit, so that you can pass literalFloats into methods that requirePosZFloat, and get the same compile-time checking you get when callingPosZFloat.applyexplicitly. Here's an example:scala> def invert(pos: PosZFloat): Float = Float.MaxValue - pos invert: (pos: org.scalactic.anyvals.PosZFloat)Float scala> invert(1.1fF) res5: Float = 3.4028235E38 scala> invert(Float.MaxValue) res6: Float = 0.0 scala> invert(-1.1fF) <console>:15: error: PosZFloat.apply can only be invoked on a non-negative (i >= 0.0f) floating point literal, like PosZFloat(1.1fF). invert(0.0F) ^ scala> invert(-1.1fF) <console>:15: error: PosZFloat.apply can only be invoked on a non-negative (i >= 0.0f) floating point literal, like PosZFloat(1.1fF). invert(-1.1fF) ^This example also demonstrates that the PosZFloatcompanion object also defines implicit widening conversions when no loss of precision will occur. This makes it convenient to use aPosZFloatwhere aFloator wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Float.MaxValue - pos. AlthoughFloat.MaxValueis aFloat, which has no-method that takes aPosZFloat(the type ofpos), you can still subtractpos, because thePosZFloatwill be implicitly widened toFloat.
-   final  class PosZInt extends AnyValAn AnyValfor non-negativeInts.An AnyValfor non-negativeInts.Because PosZIntis anAnyValit will usually be as efficient as anInt, being boxed only when anIntwould have been boxed.The PosZInt.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingPosZInt.applywith a literalIntvalue will either produce a validPosZIntinstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> PosZInt(42) res0: org.scalactic.anyvals.PosZInt = PosZInt(42) scala> PosZInt(-1) <console>:14: error: PosZInt.apply can only be invoked on a non-negative (i >= 0) literal, like PosZInt(42). PosZInt(-1) ^PosZInt.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toPosZInt.apply, you'll get a compiler error that suggests you use a different factor method,PosZInt.from, instead:scala> val x = 1 x: Int = 1 scala> PosZInt(x) <console>:15: error: PosZInt.apply can only be invoked on a non-negative integer literal, like PosZInt(42). Please use PosZInt.from instead. PosZInt(x) ^The PosZInt.fromfactory method will inspect the value at runtime and return anOption[PosZInt]. If the value is valid,PosZInt.fromwill return aSome[PosZInt], else it will return aNone. Here's an example:scala> PosZInt.from(x) res3: Option[org.scalactic.anyvals.PosZInt] = Some(PosZInt(1)) scala> val y = 0 y: Int = 0 scala> PosZInt.from(y) res4: Option[org.scalactic.anyvals.PosZInt] = None The PosZInt.applyfactory method is marked implicit, so that you can pass literalInts into methods that requirePosZInt, and get the same compile-time checking you get when callingPosZInt.applyexplicitly. Here's an example:scala> def invert(pos: PosZInt): Int = Int.MaxValue - pos invert: (pos: org.scalactic.anyvals.PosZInt)Int scala> invert(1) res0: Int = 2147483646 scala> invert(Int.MaxValue) res1: Int = 0 scala> invert(0) <console>:15: error: PosZInt.apply can only be invoked on a non-negative (i >= 0) integer literal, like PosZInt(42). invert(0) ^ scala> invert(-1) <console>:15: error: PosZInt.apply can only be invoked on a non-negative (i >= 0) integer literal, like PosZInt(42). invert(-1) ^This example also demonstrates that the PosZIntcompanion object also defines implicit widening conversions when either no loss of precision will occur or a similar conversion is provided in Scala. (For example, the implicit conversion fromIntto Float in Scala can lose precision.) This makes it convenient to use aPosZIntwhere anIntor wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Int.MaxValue - pos. AlthoughInt.MaxValueis anInt, which has no-method that takes aPosZInt(the type ofpos), you can still subtractpos, because thePosZIntwill be implicitly widened toInt.
-   final  class PosZLong extends AnyValAn AnyValfor non-negativeLongs.An AnyValfor non-negativeLongs.Because PosZLongis anAnyValit will usually be as efficient as anLong, being boxed only when anLongwould have been boxed.The PosZLong.applyfactory method is implemented in terms of a macro that checks literals for validity at compile time. CallingPosZLong.applywith a literalLongvalue will either produce a validPosZLonginstance at run time or an error at compile time. Here's an example:scala> import anyvals._ import anyvals._ scala> PosZLong(42) res0: org.scalactic.anyvals.PosZLong = PosZLong(42) scala> PosZLong(-1) <console>:14: error: PosZLong.apply can only be invoked on a non-negative (i >= 0L) integer literal, like PosZLong(42). PosZLong(-1) ^PosZLong.applycannot be used if the value being passed is a variable (i.e., not a literal), because the macro cannot determine the validity of variables at compile time (just literals). If you try to pass a variable toPosZLong.apply, you'll get a compiler error that suggests you use a different factor method,PosZLong.from, instead:scala> val x = 42L x: Long = 42 scala> PosZLong(x) <console>:15: error: PosZLong.apply can only be invoked on an long literal, like PosZLong(42). Please use PosZLong.from instead. PosZLong(x) ^The PosZLong.fromfactory method will inspect the value at runtime and return anOption[PosZLong]. If the value is valid,PosZLong.fromwill return aSome[PosZLong], else it will return aNone. Here's an example:scala> PosZLong.from(x) res3: Option[org.scalactic.anyvals.PosZLong] = Some(PosZLong(42)) scala> val y = -1L y: Long = -1 scala> PosZLong.from(y) res4: Option[org.scalactic.anyvals.PosZLong] = None The PosZLong.applyfactory method is marked implicit, so that you can pass literalLongs into methods that requirePosZLong, and get the same compile-time checking you get when callingPosZLong.applyexplicitly. Here's an example:scala> def invert(pos: PosZLong): Long = Long.MaxValue - pos invert: (pos: org.scalactic.anyvals.PosZLong)Long scala> invert(1L) res5: Long = 9223372036854775806 scala> invert(Long.MaxValue) res6: Long = 0 scala> invert(-1L) <console>:15: error: PosZLong.apply can only be invoked on a non-negative (i >= 0L) integer literal, like PosZLong(42L). invert(-1L) ^This example also demonstrates that the PosZLongcompanion object also defines implicit widening conversions when either no loss of precision will occur or a similar conversion is provided in Scala. (For example, the implicit conversion fromLongto Double in Scala can lose precision.) This makes it convenient to use aPosZLongwhere aLongor wider type is needed. An example is the subtraction in the body of theinvertmethod defined above,Long.MaxValue - pos. AlthoughLong.MaxValueis aLong, which has no-method that takes aPosZLong(the type ofpos), you can still subtractpos, because thePosZLongwill be implicitly widened toLong.
Value Members
-    object CompileTimeAssertions extends CompileTimeAssertionsCompanion object that facilitates the importing of CompileTimeAssertionsmembers as an alternative to mixing in the trait.
-    object EndObject that can be used as an endpoint for NonEmptyListconstruction expressions that use the cons (::) operator.Object that can be used as an endpoint for NonEmptyListconstruction expressions that use the cons (::) operator.Here's an example: scala> 1 :: 2 :: 3 :: End res0: org.scalactic.NonEmptyList[Int] = NonEmptyList(1, 2, 3) Note that unlike Nil, which is an instance ofList[Nothing],Endis not an instance ofNonEmptyList[Nothing], because there is no emptyNonEmptyList:scala> Nil.isInstanceOf[List[_]] res0: Boolean = true scala> End.isInstanceOf[NonEmptyList[_]] res1: Boolean = false 
-    object FiniteDoubleThe companion object for FiniteDoublethat offers factory methods that produceFiniteDoubles, implicit widening conversions fromFiniteDoubleto other numeric types, and maximum and minimum constant values forFiniteDouble.
-    object FiniteFloatThe companion object for FiniteFloatthat offers factory methods that produceFiniteFloats, implicit widening conversions fromFiniteFloatto other numeric types, and maximum and minimum constant values forFiniteFloat.
-    object NegDoubleThe companion object for NegDoublethat offers factory methods that produceNegDoubles, implicit widening conversions fromNegDoubleto other numeric types, and maximum and minimum constant values forNegDouble.
-    object NegFiniteDoubleThe companion object for NegFiniteDoublethat offers factory methods that produceNegFiniteDoubles, implicit widening conversions fromNegFiniteDoubleto other numeric types, and maximum and minimum constant values forNegFiniteDouble.
-    object NegFiniteFloatThe companion object for NegFiniteFloatthat offers factory methods that produceNegFiniteFloats, implicit widening conversions fromNegFiniteFloatto other numeric types, and maximum and minimum constant values forNegFiniteFloat.
-    object NegFloatThe companion object for NegFloatthat offers factory methods that produceNegFloats, implicit widening conversions fromNegFloatto other numeric types, and maximum and minimum constant values forNegFloat.
-    object NegIntThe companion object for NegIntthat offers factory methods that produceNegInts, implicit widening conversions fromNegIntto other numeric types, and maximum and minimum constant values forNegInt.
-    object NegLongThe companion object for NegLongthat offers factory methods that produceNegLongs, implicit widening conversions fromNegLongto other numeric types, and maximum and minimum constant values forNegLong.
-    object NegZDoubleThe companion object for NegZDoublethat offers factory methods that produceNegZDoubles, implicit widening conversions fromNegZDoubleto other numeric types, and maximum and minimum constant values forNegZDouble.
-    object NegZFiniteDoubleThe companion object for NegZFiniteDoublethat offers factory methods that produceNegZFiniteDoubles, implicit widening conversions fromNegZFiniteDoubleto other numeric types, and maximum and minimum constant values forNegZFiniteDouble.
-    object NegZFiniteFloatThe companion object for NegZFiniteFloatthat offers factory methods that produceNegZFiniteFloats, implicit widening conversions fromNegZFiniteFloatto other numeric types, and maximum and minimum constant values forNegZFiniteFloat.
-    object NegZFloatThe companion object for NegZFloatthat offers factory methods that produceNegZFloats, implicit widening conversions fromNegZFloatto other numeric types, and maximum and minimum constant values forNegZFloat.
-    object NegZIntThe companion object for NegZIntthat offers factory methods that produceNegZInts, implicit widening conversions fromNegZIntto other numeric types, and maximum and minimum constant values forNegZInt.
-    object NegZLongThe companion object for NegZLongthat offers factory methods that produceNegZLongs, implicit widening conversions fromNegZLongto other numeric types, and maximum and minimum constant values forNegZLong.
-    object NonEmptyArrayCompanion object for class NonEmptyArray.
-    object NonEmptyListCompanion object for class NonEmptyList.
-    object NonEmptyMapCompanion object for class NonEmptyMap.
-    object NonEmptySetCompanion object for class NonEmptySet.
-    object NonEmptyStringCompanion object for class NonEmptyString.
-    object NonEmptyVectorCompanion object for class NonEmptyVector.
-    object NonZeroDoubleThe companion object for NonZeroDoublethat offers factory methods that produceNonZeroDoubles, implicit widening conversions fromNonZeroDoubleto other numeric types, and maximum and minimum constant values forNonZeroDouble.
-    object NonZeroFiniteDoubleThe companion object for NonZeroFiniteDoublethat offers factory methods that produceNonZeroFiniteDoubles, implicit widening conversions fromNonZeroFiniteDoubleto other numeric types, and maximum and minimum constant values forNonZeroFiniteDouble.
-    object NonZeroFiniteFloatThe companion object for NonZeroFiniteFloatthat offers factory methods that produceNonZeroFiniteFloats, implicit widening conversions fromNonZeroFiniteFloatto other numeric types, and maximum and minimum constant values forNonZeroFiniteFloat.
-    object NonZeroFloatThe companion object for NonZeroFloatthat offers factory methods that produceNonZeroFloats, implicit widening conversions fromNonZeroFloatto other numeric types, and maximum and minimum constant values forNonZeroFloat.
-    object NonZeroIntThe companion object for NonZeroIntthat offers factory methods that produceNonZeroInts, implicit widening conversions fromNonZeroIntto other numeric types, and maximum and minimum constant values forNonZeroInt.
-    object NonZeroLongThe companion object for NonZeroLongthat offers factory methods that produceNonZeroLongs, implicit widening conversions fromNonZeroLongto other numeric types, and maximum and minimum constant values forNonZeroLong.
-    object NumericCharThe companion object for NumericCharthat offers factory methods that produceNumericChars and maximum and minimum constant values forNumericChar.
-    object NumericStringThe companion object for NumericStringthat offers factory methods that produceNumericStrings.
-    object PosDoubleThe companion object for PosDoublethat offers factory methods that producePosDoubles, implicit widening conversions fromPosDoubleto other numeric types, and maximum and minimum constant values forPosDouble.
-    object PosFiniteDoubleThe companion object for PosFiniteDoublethat offers factory methods that producePosFiniteDoubles, implicit widening conversions fromPosFiniteDoubleto other numeric types, and maximum and minimum constant values forPosFiniteDouble.
-    object PosFiniteFloatThe companion object for PosFiniteFloatthat offers factory methods that producePosFiniteFloats, implicit widening conversions fromPosFiniteFloatto other numeric types, and maximum and minimum constant values forPosFiniteFloat.
-    object PosFloatThe companion object for PosFloatthat offers factory methods that producePosFloats, implicit widening conversions fromPosFloatto other numeric types, and maximum and minimum constant values forPosFloat.
-    object PosIntThe companion object for PosIntthat offers factory methods that producePosInts, implicit widening conversions fromPosIntto other numeric types, and maximum and minimum constant values forPosInt.
-    object PosLongThe companion object for PosLongthat offers factory methods that producePosLongs, implicit widening conversions fromPosLongto other numeric types, and maximum and minimum constant values forPosLong.
-    object PosZDoubleThe companion object for PosZDoublethat offers factory methods that producePosZDoubles, implicit widening conversions fromPosZDoubleto other numeric types, and maximum and minimum constant values forPosZDouble.
-    object PosZFiniteDoubleThe companion object for PosZFiniteDoublethat offers factory methods that producePosZFiniteDoubles, implicit widening conversions fromPosZFiniteDoubleto other numeric types, and maximum and minimum constant values forPosZFiniteDouble.
-    object PosZFiniteFloatThe companion object for PosZFiniteFloatthat offers factory methods that producePosZFiniteFloats, implicit widening conversions fromPosZFiniteFloatto other numeric types, and maximum and minimum constant values forPosZFiniteFloat.
-    object PosZFloatThe companion object for PosZFloatthat offers factory methods that producePosZFloats, implicit widening conversions fromPosZFloatto other numeric types, and maximum and minimum constant values forPosZFloat.
-    object PosZIntThe companion object for PosZIntthat offers factory methods that producePosZInts, implicit widening conversions fromPosZIntto other numeric types, and maximum and minimum constant values forPosZInt.
-    object PosZLongThe companion object for PosZLongthat offers factory methods that producePosZLongs, implicit widening conversions fromPosZLongto other numeric types, and maximum and minimum constant values forPosZLong.