Boolean._extension

trait _extension

Boolean Extension Methods

Extension methods universaly avaialble for type scala.Boolean

Source
_extension.scala
class Object
trait Matchable
class Any

Def

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

To option

To option

Returns Boolean.Opt for current value

 val o: Boolean.Opt = true.?
Source
_extension.scala
@targetName("Opt")
inline def ?[A](inline v: => A): Opt.type[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(\/)

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
_extension.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
_extension.scala

To

inline def Int: Int

To Int

To Int

Int constructor attached to Boolean

true is converted to 1, false to 0

Source
_extension.scala