Skip to content

std/discrete

Import with import std/discrete.

Interfaces

interface Discrete {
    fn next(value: self): Maybe<self>
    fn steps_between(start: self, end: self): Maybe<Int>
}

Protocol for values with a well-defined next value.

A discrete type’s values come in separate steps rather than a continuous space: after 1 comes 2, and after one valid Codepoint comes the next valid Codepoint. Dense or successor-less types like Float and String can be ordered, but they do not have one obvious next value.

Range<'T> implements Iterable<'T> when T is both Comparable and Discrete, so range syntax can produce lazy sequences for discrete domains like Int and Codepoint while remaining an interval value for dense or successor-less domains like Float and String.