_methods

trait _methods

Boolean Extension Methods

Extension methods universaly avaialble for type scala.Boolean

Source
_methods.scala
class java.lang.Object
trait scala.Matchable
class Any

Def

@targetName("Opt")
inline def ?: Boolean.Opt

To option

To option

Returns Boolean.Opt for current value

 val o: Boolean.Opt = true.?
Source
_methods.scala
@targetName("Opt")
inline def ?(v: => A): Opt[A]

To given value option

To given value option

Returns given value option if base Boolean is true, and void option if false

 var b = true

 (b ? "Foo").tp  // Prints   Opt(Foo)

 b = false

 (b ? "Foo").tp  // Prints   Opt(VOID)

Note: This operation can be used as a conditional function

 var b = true

 (b ? "Foo" or "Bar").tp  // Prints   Foo

 b = false

 (b ? "Foo" or "Bar").tp  // Prints   Bar
Source
_methods.scala
inline def not: Boolean

Reversed Boolean

Reversed Boolean

This is a postfix operation equivalent to !, ie. true.not == !true

 var b = true

 b.not  // Prints   false

 b = false

 b.not  // Prints   true

Note: This operation is inlined and can be used without performance worries

Source
_methods.scala
inline def toInt: Int

Make Int

Make Int

Int constructor attached to Boolean

true is converted to 1, false to 0

Source
_methods.scala
inline def toRef: java.lang.Boolean

To Boolean object

To Boolean object

val b = true

b.toRef
// is inlined as
java.lang.Boolean.valueOf(b)
Source
_methods.scala