Range

abstract class Range[A] extends Able.Contain[A] with Able.Empty

Value Range

Range is logically defined with the following defs:

  • start
  • end,
  • and ordering, which makes the above meaningful

Range has a notion that an element can be within the range, i.e. between start and end, or outside

Note. Scala provided range structures (scala.collection.immutable.Range and scala.collection.immutable.NumericRange) are implemented more as collections and this class is designed to close this void focusing on basic range features.

Source
__.scala
trait Able.Contain[Range.A]
class java.lang.Object
trait scala.Matchable
class Any
class AnyRef.G.Range.X.Base[AnyRef.G.Range.X.Base.A, AnyRef.G.Range.X.Base.THIS]
class Period
class AnyRef.G.Range.X.Abstract[AnyRef.G.Range.X.Abstract.A]
class AnyRef.G.Range[AnyRef.G.Range.A]
class Byte.G.Range[Byte.G.Range.A]
class Char.G.Range[Char.G.Range.A]
class Double.G.Range[Double.G.Range.A]
class Float.G.Range[Float.G.Range.A]
class Int.G.Range[Int.G.Range.A]
class Long.G.Range[Long.G.Range.A]
class Short.G.Range[Short.G.Range.A]

Def

def contains(v: Range[A]): Boolean

Check if within

Check if within

Returns true if this range contains specified range

 (1 <> 9) contains (3 <> 7)  // Returns: true

 (1 <> 5) contains (3 <> 7)  // Returns: false
Source
__.scala
def contains(v: A): Boolean

Check if within

Check if within

Returns true if this range contains specified value

 (1 <> 9) contains 3  // Returns: true
Source
__.scala
def end: A

Make value

Make value

End value of the range

Source
__.scala
def endIsIn: Boolean

Inclusive check

Inclusive check

If true, the end value is inclusive

 (10 <>> 15) contains 15   // Returns: false

 // Exclusive 15 does not contain 15
Source
__.scala
override def equals(v: Any): Boolean
Definition Classes
Any
Source
__.scala
def isEmpty: Boolean

Empty check

Empty check

Checks if the range is able contain anything.

For empty range the start and end values are the same and the end value is not inclusive

Source
__.scala
def join(v: A): this.type

Extend to

Extend to

This range is extended to contain the specified value

 'A' <> 'C' extendTo 'G' // Returns: A <> G

 'A' <> 'C' extendTo 'B' // Returns: A <> C
Source
__.scala
def join(v: Range[A]): this.type

Union

Union

Returns range with out-most reaches of this and specified

 'A' <> 'C' join 'X' <> 'Z' // Returns: A <> Z
Source
__.scala

Ordering

Ordering

Ordering defining range

Ordering defining type elements comparison

Source
__.scala

Optional intersection

Optional intersection

Optionally returns common intersection of this and that

 1 <> 6 overlapOpt 3 <> 9  // Returns: Opt(3 <> 6)

 1 <> 3 overlapOpt 6 <> 9  // Returns: Opt(VOID)
Source
__.scala
def overlaps(r: Range[A]): Boolean

Overlap check

Overlap check

Returns true if two ranges overlap

Source
__.scala
inline def raw(using sp: Specialized.Primitive[A]): s.Range

Primitive range

Primitive range

Returns primitive specialized range implementation.

The method will not compile for reference types.

Source
__.scala
def start: A

From value

From value

Start value of the range

Source
__.scala
def stepStream(f: A => A): Stream[A]

Stream of calculated values

Stream of calculated values

Returns a stream starting with the first range value. Every next value is calculated by applying the given function to the prior value. The stream ends when the function result is no longer within range.

 (1 <> 10).stepStream( _ + 3).tp  // Prints: Stream(1, 4, 7, 10)
Source
__.scala

Extension

inline def ~~[A](using s: Able.Sequence[A]): Stream[A]

Alias to "stream"

Alias to "stream"

Source
__.scala
def convert[A](f: A => B)(using o: Ordering[B]): Range[B]
Source
__.scala
def stream[A](using s: Able.Sequence[A]): Stream[A]
Source
__.scala