_methods

trait _methods

Every Type Extension Methods

Extension methods universaly avaialble for all types

Note. For primitives these methods often have efficient overrides.

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

Def

@scala.annotation.targetName("addSpaced")
inline def +-[A](v: B)(using inline ta: Given.DocTag[A], inline tb: Given.DocTag[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 huge mistake, because this not 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
@scala.annotation.targetName("range")
inline def <>[A](inline to: A)(using inline o: scala.Ordering[A], inline t: Given.RangeTag[A, RNG]): RNG

Range

Range

Returns Range from current to given value

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

Note. An Ordering be implicitly available

Source
__.scala
@scala.annotation.targetName("rangeX")
inline def <>>[A](inline to: A)(using inline o: scala.Ordering[A], inline t: Given.RangeTag[A, RNG]): RNG

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
@scala.annotation.targetName("opt")
inline def ?[A](using inline t: Given.OptTag[A, OPT]): OPT

To option

To option

Returns Opt for current value

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

Note. Option will be empty if value is 'null'

Source
__.scala
@scala.annotation.targetName("result")
inline def ??[A]: Result[A]

To result

To result

Returns Result for current value

 val o : Result[String] = "Foo".??
Source
__.scala
@scala.annotation.targetName("selfView")
inline def ^[A]: Any._methods._view[A]

Self view

Self view

Returns additional "view" 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).^(_.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 doc[A](using inline dd: Given.DocTag[A]): Doc

Get Doc

Get Doc

Returns Doc object describing current instance

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

Source
__.scala
inline def in[A](inline c: CONTAINER)(using inline t: Given.WithinTag[A, CONTAINER]): 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).~.><

 (5 in pack).tp    // Prints true

Note. This operation is heavily overloaded, to provide performance close to directly written efficient comparison code

Source
__.scala
inline def isVoid[A](using inline t: Given.VoidTag[A]): Boolean

Void check

Void check

Returns true if target is void

Source
__.scala
inline def nonVoid[A](using inline t: Given.VoidTag[A]): Boolean
Source
__.scala
@scala.annotation.targetName("self_View")
inline def self_^[A]: Any._methods._view[A]

Self view

Self view

self_^ is functionally identical to ^, and should be used when ^ struggles

^ occasionally does not work, because it is locally overridden with other functionality (for example on Int, Long it does some bit ops)

Source
__.scala
inline def tag[A](using inline dd: Given.DocTag[A]): String

Make String

Make String

Returns String representation of base type value.

.tag has to universally be used instead of Java .toString. This is due opaque types, which by definition cannot overwrite .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 inline dd: Given.DocTag[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).~.tp
 // vs.
 println((1 <> 10).~.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