Steppable

public protocol Steppable

A type whose values can be stepped one position at a time. Underpins for-in over integer ranges and any other "next/previous" walk where the step size is implicit (1 for integers).

successor and predecessor should be inverses for every interior value; behaviour at the type's edges (Int64.maxValue.successor(), for example) follows the same wrapping rules as add/subtract.

Methods

func distance(to: Self) -> Int64

The number of successor() steps from self to other (negative when other precedes self). For integers this is other - self.

This is the O(1) stride distance — it lets range iterators carry a remaining-element counter instead of a boolean "finished" flag, which is what keeps for x in a..=b unrollable (a counter is an induction variable the optimizer can reason about; a flag is not).

The result must fit in Int64. For spans wider than Int64 (only reachable via near-full-width ranges, which never terminate in practice) the value wraps, following the same edge rule as successor/predecessor.

func predecessor() -> Self

The previous value in the sequence. For integers this is self - 1.

func successor() -> Self

The next value in the sequence. For integers this is self + 1.

Defined in lang/std/numeric/numeric.ks