1 package frost.core
2
3 ====================================================================================================
4 Represents a range between two values. `Range` contains a `min`, `max`, and flag to determine
5 inclusive vs. exclusive ranges; the `inclusive` flag is understood to refer to the `max` endpoint
6 only, with `min` always being included in the `Range`.
7
8 The exclusive range (`..`) and inclusive range (`...`) operators in Frost provide a shorthand syntax
9 for creating `Range` and [SteppedRange] objects.
10 ====================================================================================================
11 @specialize
12 class Range<T:Value?> : Value {
13 ================================================================================================
14 The range's starting point.
15 ================================================================================================
16 def min:T
17
18 ================================================================================================
19 The range's ending point.
20 ================================================================================================
21 def max:T
22
23 ================================================================================================
24 `true` if the range includes its maximum value.
25 ================================================================================================
26 def inclusive:Bit
27
28 ================================================================================================
29 Creates a new `Range`.
30 ================================================================================================
31 init(min:T, max:T, inclusive:Bit) {
32 self.min := min
33 self.max := max
34 self.inclusive := inclusive
35 }
36
37 @override
38 function get_toString():String {
39 def result := MutableString()
40 if min !== null {
41 result.append(min!)
42 }
43 if inclusive {
44 result.append("...")
45 }
46 else {
47 result.append("..")
48 }
49 if max !== null {
50 result.append(max!)
51 }
52 return result.finish()
53 }
54 }