Self View Methods
Self view is another library available for all types, but it has to be activated by calling a universal ".self" method on original value.
For example:
val pack: Pack[String] = "FOO".self.pack
Due to opaque implementation, calling self view methods incures no overhead as if they were called directly on base value.
A common use case is to manipulate an object within expression context:
val a : Array[String] = new Array[String](1).self(_(0)="A")
because all calls are inlined, the above expression is equivalent to:
val a : Array[String] = new Array[String](1)
a(0)="A"
- Source
- Self.scala
Def
Process
Process
Processes value with given function
Returns the base value itself
val a : Array[String] = new Array[String](2).self(a => { a(0)="A"; a(1)="B" })
- Source
- Self.scala
Hash code
Hash code
Returns alphanumeric hash code 4 characters long
It is shorter and display friendly compared to Java hash.
It is not meant to be used for calculations, like in Hashtable, but rather for display purposes.
- Source
- Self.scala
Empty check
Empty check
Returns true
if value is empty, false
- otherwise.
Any.Def.Empty is available for most known types, but can be defined for new.
- Source
- Self.scala
Void check
Void check
Returns true
if value is null or void, false
- otherwise
Note. This method includes 'null' check compared to 'isVoid' on base value.
- Source
- Self.scala
Convert To
Convert To
Converts base value with given function
Returns the result of the conversion
- Source
- Self.scala
Conditionally change value
Conditionally change value
Changes base value with the given function, if condition is right
Returns new value or old value
Note:
var s = "AB"
s = s.self.mapIf(_.length == 2, _ + "C")
// gets compiled into
s = if(s.length == 2) s + "C" else s
```
- Source
- Self.scala
Non empty check
Non empty check
Returns true
if value is not not empty, false
- otherwise
Any.Def.Empty is available for most known types, but can be defined for new.
- Source
- Self.scala
Non void check
Non void check
Returns true
if value is not null and not void, false
- otherwise
Note. This method includes 'null' check compared to 'nonVoid' on base value.
- Source
- Self.scala
Self stream
Self stream
Creates a stream with this sigle value
The following lines are inlined and produce same JVM code:
val s1 : Stream[String] = "Foo".self.stream
// same as
val s2 : Stream[String] = Stream("Foo")
- Source
- Self.scala
Type name
Type name
Returns type name, which is class name for reference types and given tagged name for raw types
- Source
- Self.scala