_methods

trait _Methods

Universal Extension Methods

Extension methods avaialble for all types

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

Def

@targetName("addSpaced")
inline def +-[A](v: B)(using ta: Any.Def.Tag[A], tb: Any.Def.Tag[B]): String

Any to String add with space

Any to String add with space

Concatenates this and given object string tags with one space in between

true +- 1 +- 2 +- 3 +- 'A' +- 10.Percent tp() // Prints true 1 2 3 A 10%

Note. Java supports AnyRef + AnyRef, resulting in their String representation concatenation. Scala 2 also used to support this, which was a big mistake, because this not really important + operation, due to it global nature, would interfere with all attempts to use + for anything else. Scala 3 got rid of this for good. Scalqa re-introduces this usefull functionality with such a weired name "+-", hoping it will not pose naming conflits

Source
__.scala
@targetName("range")
inline def <>[A](to: A)(using o: Ordering[A])(using s: Specialized[A]): s.Range

Range

Range

Returns Range from current to given value

 ("AAA" <> "BBB").tp  // Prints  AAA <> BBB

Note. An Ordering must be implicitly available

Source
__.scala
@targetName("rangeX")
inline def <>>[A](to: A)(using o: Ordering[A])(using s: Specialized[A]): s.Range

Exclusive end range

Exclusive end range

Returns <> from current to given value exclusive

 ("AAA" <>> "BBB").tp  // Prints  AAA <>> BBB

Note. An Ordering must be implicitly available

Source
__.scala
@targetName("opt")
inline def ?[A](using s: Specialized[A]): s.Opt

To option

To option

Returns Opt for current value

 val o : Opt[String] = "Foo".?

Result will be empty option if value is 'null', but non empty for void values. Use .?? instead if void or empty check is required.

Source
__.scala
@targetName("nonEmptyOpt")
inline def ??[A](using e: Opt[Any.Def.Empty[A]])(using d: Any.Def.Void[A]): Opt[A]

To non-empty value option

To non-empty value option

Returns base value as an option.

Unlike general .? method, this method will create empty option for void or empty values

 val p: Stream[Int]=VOID

 p.?.tp    // prints: Opt(scalqa.val.pack.z.Void)

 p.??.tp  // prints: Opt(VOID)

This method can even safely check Stream for emptiness, returning Stream with original values

def s : Stream[Int] = (1 <> 3).stream.dropFirst(3)

s.??.tp  // prints: Opt(VOID)
s.?.tp   // prints: Opt(Stream())
Source
__.scala
inline def doc[A](using d: Any.Def.Doc[A]): Doc

Get Doc

Get Doc

Returns Doc object describing current instance

Reference types can implement Able.Doc, opaque types can provide implicit Any.Def.Doc, in any case this operation will retrieve Doc or will create a default one, if none is found.

Source
__.scala
inline def in[A](c: CONTAINER)(using d: Any.Def.Contains[CONTAINER, A]): Boolean

Is within

Is within

Returns true if this instance is contained by given container.

 val range = 1 <> 10

 (5 in range).tp   // Prints true

 val pack = (1 <> 10).stream.pack

 (5 in pack).tp    // Prints true

Note. This operation is Macro optimized for Tuples from 2 to 12, so the following check will be ultimatly efficent with no Tuple allocation:

 val s = "ABC"

 s in ("XYZ","BBC","CBC")
Source
__.scala
inline def isVoid[A](using d: Any.Def.Void[A]): Boolean

Void check

Void check

Returns true if target is void

Note: Operation can fail for null value, use .self.isVoid if null check is required

Source
__.scala
inline def nonVoid[A](using d: Any.Def.Void[A]): Boolean

Not void check

Not void check

Returns true if target is non void

Note: Operation can fail for null value, use .self.nonVoid if null check is required

Source
__.scala
inline def notIn[A](c: CONTAINER)(using d: Any.Def.Contains[CONTAINER, A]): Boolean

Is not within

Is not within

Reverse "in" method

Source
__.scala
inline def self[A]: Any._methods.Self[A]

Self view

Self view

Returns additional "self" library available to this instance

The most popular feature is doing some processing within context of an anonimous function

val a: Array[Int] = new Array[Int](3).self(_.fill(5))

// Compare to

val b: Array[Int] = { val a = new Array[Int](3); a.fill(5); a }

Note. Due to opaque implementation and inlining, there is no performance difference in the above two cases

Source
__.scala
inline def tag[A](using t: Any.Def.Tag[A]): String

Make String

Make String

Returns String representation of base value.

.tag has to universally be used instead of Java .toString. This is due to opaque types, which by definition cannot override .toString, but have facility to provide correct .tag.

In traditional objects, .tag by default calls .toString.

val v: Time.Length =  100.Seconds

v.tag.tp       // Prints 1 min 40 secs

// Compare to

v.toString.tp  // Prints 100000000000
Source
__.scala
inline def tp[A](using t: Any.Def.Tag[A]): Unit

Tag print

Tag print

tp should be pronounced as "tip"

tp is a functional equivalent to println for debugging, education and demonstration purposes

tp should never be inside a production program, println should be used instead. Searching code for tp should immediately locate debugging fragments.

// Compare:

1.tp
// vs.
println(1.tag)

(1 <> 10).stream.tp
// vs.
println((1 <> 10).stream.tag)

100.Seconds.tp
// vs.
println(100.Seconds.tag)

Also, there is postfix like overload of tp on String type

"Results:" +- 1 +- 2 +- 3 +- 4.Percent tp()
// vs.
println("Results:" +- 1 +- 2 +- 3 +- 4.Percent)
Source
__.scala