Light
Dark
System
v3latest
v3latest
v2
v1

Custom Datatypes

Represents an interval between values.

The Range type behaves the same as the EdgeDB range type. Ranges can have a lower and upper boundary, which can be inclusive or exclusive, or omitted completely (null). By default, the lower boundary is inclusive, and the upper boundary exclusive.

Depending on the type of the range, T, the range is either discrete or continuous. Discrete range types: Range<int> Continuous range types: Range<double>, Range<DateTime> Discrete ranges are normalised upon creation, such that the lower boundary becomes inclusive, and the upper boundary becomes exclusive.

If a range can contain no values, it is considered ‘empty’. Empty ranges are all considered equal to each other. An empty range can be created either by the Range.empty() constructor, creating a range where the lower and upper boundaries are equal, and at least one boundary is exclusive, or as the result of some operation on a range.

Copy
Range<T>(
  T? lower,
  T? upper,
  {bool? incLower,
  bool? incUpper}
)

Creates a new Range.

If not given, incLower and incUpper default to true and false respectively.

Copy
Range<T>.empty()

Creates a new empty Range of type T.

Copy
int get hashCode

The hash code for this object.

Copy
bool get incLower

Whether the lower boundary is inclusive. Is always false for unspecified boundaries and empty ranges.

Copy
bool get incUpper

Whether the upper boundary is inclusive. Is always false for unspecified boundaries and empty ranges.

Copy
bool get isEmpty

Whether the range is empty.

Copy
T? get lower

The lower boundary of the range, if it exists.

Copy
T? get upper

The upper boundary of the range, if it exists.

Copy
int compareTo(
  Range<T> other
)

Compares this object to another object.

Returns a value like a Comparator when comparing this to other. That is, it returns a negative integer if this is ordered before other, a positive integer if this is ordered after other, and zero if this and other are ordered together.

The other argument must be a value that is comparable to this object.

Copy
bool contains(
  T element
)

Checks whether element is within this range.

Copy
bool containsRange(
  Range<T> range
)

Checks whether range is entirely within this range.

Copy
bool overlaps(
  Range<T> other
)

Checks whether other range overlaps this range.

Copy
dynamic toJSON()
Copy
String toString()

String representation of the range.

Inclusive boundaries are denoted by [] brackets, and exclusive boundaries by (). If the range is empty, returns the string 'empty'.

Copy
Iterable<T> unpack(
  {Object? step}
)

If the range is discrete and no step is provided, returns an Iterable of all values in the range. Otherwise returns an Iterable of each value starting at the lower bound, increasing by step up to the upper bound.

An error is thrown if the range is unbounded (ie. either lower or upper are null), or the step parameter is not given for non-discrete ranges.

Copy
Range<T> operator *(
  Range<T> other
)

Returns the intersection of two ranges.

Copy
Range<T> operator +(
  Range<T> other
)

Returns the union of two ranges.

Throws an error if the result is not a single continuous range.

Copy
Range<T> operator -(
  Range<T> other
)

Subtracts one range from another.

Throws an error if the result is not a single continuous range.

Copy
bool operator <(
  Range<T> other
)

Returns whether this range is before the other range.

A range is considered to be ordered before another range if its lower bound is lower than the other. If the lower bounds are equal, the upper bounds are checked. An empty range is considered lower than a non-empty range, and unspecified lower/upper bounds are considered lower/greater than specified lower/upper bounds respectively.

Copy
bool operator <=(
  Range<T> other
)

Returns whether this range is before or equal to the other range.

A range is considered to be ordered before another range if its lower bound is lower than the other. If the lower bounds are equal, the upper bounds are checked. An empty range is considered lower than a non-empty range, and unspecified lower/upper bounds are considered lower/greater than specified lower/upper bounds respectively.

Copy
bool operator ==(
  Object other
)

Returns whether two ranges are equal.

Copy
bool operator >(
  Range<T> other
)

Returns whether this range is after the other range.

A range is considered to be ordered after another range if its lower bound is greater than the other. If the lower bounds are equal, the upper bounds are checked. An empty range is considered lower than a non-empty range, and unspecified lower/upper bounds are considered lower/greater than specified lower/upper bounds respectively.

Copy
bool operator >=(
  Range<T> other
)

Returns whether this range is after or equal to the other range.

A range is considered to be ordered after another range if its lower bound is greater than the other. If the lower bounds are equal, the upper bounds are checked. An empty range is considered lower than a non-empty range, and unspecified lower/upper bounds are considered lower/greater than specified lower/upper bounds respectively.

Represents an amount of memory in bytes.

Uses the base-2 KiB notation (1024 bytes), instead of the more ambiguous ‘kB’, which can mean 1000 or 1024 bytes.

Copy
ConfigMemory(
  int _bytes
)
Copy
ConfigMemory.parse(
  String mem
)
Copy
int get bytes
Copy
num get gibibytes
Copy
num get kibibytes
Copy
num get mebibytes
Copy
num get pebibytes
Copy
num get tebibytes
Copy
String toString()

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.

Light
Dark
System

We use ChatGPT with additional context from our documentation to answer your questions. Not all answers will be accurate. Please join our Discord if you need more help.