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
Def
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
Check if within
Check if within
Returns true if this
range contains specified value
(1 <> 9) contains 3 // Returns: true
- Source
- __.scala
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
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
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
Union
Union
Returns range with out-most reaches of this
and specified
'A' <> 'C' join 'X' <> 'Z' // Returns: A <> Z
- 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
Primitive range
Primitive range
Returns primitive specialized range implementation.
The method will not compile for reference types.
- Source
- __.scala
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