TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
..< operator is the open-ended range operator in Kotlin, used to construct a range of values that includes the lower bound but strictly excludes the upper bound. It provides a mathematically intuitive representation of half-open intervals and serves as the native syntactic replacement for the until infix function.
Syntax and Compilation
The operator is placed between the start and end bounds:..< operator into a method call to the rangeUntil operator function. The above syntax is strictly equivalent to:
Type System Integration
The behavior and return type of the..< operator depend on the operand types:
-
Integral Types (
Int,Long,Short,Byte,Char): For discrete integral types, the operator returns a standardIterableprogression (e.g.,IntRange,LongRange). The standard library implementation ofrangeUntilfor these types explicitly guards against integer underflow. Rather than blindly calculatingend - 1to find an inclusive upper bound, the function checks the exclusive bound against the type’s minimum value (e.g.,if (to <= Int.MIN_VALUE) return IntRange.EMPTY). This ensures that an expression like0 ..< Int.MIN_VALUEsafely returns an empty range instead of underflowing toInt.MAX_VALUE.
Operator Overloading and Custom Types
Any class that implements theComparable<T> interface automatically supports the ..< operator without requiring a manual implementation of the rangeUntil member function. The standard library provides the extension operator fun <T : Comparable<T>> T.rangeUntil(that: T): OpenEndRange<T>, which handles the boundary evaluation.
rangeUntil operator function is only required for non-comparable types, or when a custom type needs to return a specialized discrete progression (such as a custom Iterable range) rather than the default continuous OpenEndRange<T>.
Behavioral Characteristics
- Ascending Order Only: The
..<operator strictly creates ascending ranges. If the left operand is greater than or equal to the right operand, the resulting range is empty (isEmpty()returnstrue). - Step Size: For integral progressions, the default step size is
1. - Interface Hierarchy: The
OpenEndRange<T>interface is distinct fromClosedRange<T>(which is generated by the..operator).OpenEndRangeexposes anendExclusiveproperty, whereasClosedRangeexposes anendInclusiveproperty.
Master Kotlin with Deep Grasping Methodology!Learn More





