_methods.Self

opaque type Self[+A]

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

inline def apply[A](f: A => U): A

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
def hash[A]: String

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
def id[A](using d: Any.Def.TypeName[A]): String

Instance id

Instance id

Id is usually type name + "@" + hash code.

Source
Self.scala
inline def isEmpty[A](using d: Any.Def.Empty[A]): Boolean

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
inline def isVoid[A](using d: Any.Def.Void[A]): Boolean

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
inline def map[A](f: A => B): B

Convert To

Convert To

Converts base value with given function

Returns the result of the conversion

Source
Self.scala
inline def mapIf[A](filter: A => Boolean, f: A => A): A

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
inline def nonEmpty[A](using d: Any.Def.Empty[A]): Boolean

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
inline def nonVoid[A](using d: Any.Def.Void[A]): Boolean

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
inline def pack[A]: Pack[A]

Self pack

Self pack

Creates a pack with this sigle value

Source
Self.scala
inline def stream[A]: Stream[A]

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
def typeName[A](using d: Any.Def.TypeName[A]): String

Type name

Type name

Returns type name, which is class name for reference types and given tagged name for raw types

Source
Self.scala