Member
Scalqa supports a concept of "void object" ("empty object"), which can be defined for many types. This is similar to 'Null Object Pattern'
Unlike 'null', void object can have methods invoked, getting some behavior pertinent to 'voidness'
Examples:
- Void Stream can be a singleton empty stream, which can be re-used for any type
- Void String is a string of zero length, which can be re-used for String type instead of null
Types with void values have to define implicit conversions from \/
class Foo
object Foo{
val void = new Foo with Void
implicit inline def xxRequest(inline v: \/) = void
}
var v: Foo = \/ // Standard void assignment
/ is a shortcut to assign empty implementations for many types
var s: ~[Int] = \/ // Assigning empty [[Stream]] of Ints
var o: Opt[String] = \/ // Assigning empty optional value of String
var i: Long.Idx = \/ // Assigning empty indexed collection of Long
Also see Any.Self.Void
A standard way to test for voidness is universal .isEmpty
method.
- Source
- VOID.scala
Scalqa supports a concept of "void object" ("empty object"), which can be defined for many types. This is similar to 'Null Object Pattern'
Unlike 'null', void object can have methods invoked, getting some behavior pertinent to 'voidness'
Examples:
- Void Stream can be a singleton empty stream, which can be re-used for any type
- Void String is a string of zero length, which can be re-used for String type instead of null
Types with void values have to define implicit conversions from \/
class Foo
object Foo{
val void = new Foo with Void
implicit inline def xxRequest(inline v: \/) = void
}
var v: Foo = \/ // Standard void assignment
/ is a shortcut to assign empty implementations for many types
var s: ~[Int] = \/ // Assigning empty [[Stream]] of Ints
var o: Opt[String] = \/ // Assigning empty optional value of String
var i: Long.Idx = \/ // Assigning empty indexed collection of Long
Also see Any.Self.Void
A standard way to test for voidness is universal .isEmpty
method.
- Source
- VOID.scala