Home

partialranges

Partial ranges are a family of range-like constructs used in some programming languages to describe a subset of a range when one bound is not specified. They are most commonly associated with Swift, where they enable concise slicing of collections and flexible pattern matching by omitting either the lower bound, the upper bound, or both.

In Swift, there are three main forms of partial ranges, each corresponding to a different way of

- PartialRangeFrom, represented by expressions like 5..., denotes a range that starts at a lower bound and

- PartialRangeThrough, represented by ...5, denotes a range that starts at the beginning and goes through the

- PartialRangeUpTo, represented by ..<5, denotes a range that starts at the beginning and goes up to

These forms conform to the RangeExpression protocol and can be used wherever a range is accepted for

Using partial ranges requires the underlying collection to support indexing by the resulting range type and,

Overall, partial ranges offer a concise way to express common subranges while preserving the clarity of range-based

omitting
a
bound:
extends
to
the
end
of
the
collection
or
sequence.
specified
upper
bound,
inclusive.
but
not
including
the
specified
bound.
subscripting
or
for
pattern
matching
in
switch
statements.
They
enable
operations
such
as
extracting
a
slice
from
a
collection
starting
at
a
given
index,
or
selecting
a
prefix
up
to
a
certain
point,
without
requiring
explicit
end
bounds.
in
the
case
of
strings
or
other
grapheme-based
collections,
careful
handling
of
indices.
When
applied
to
arrays,
partial
ranges
provide
straightforward,
zero-based
indexing
semantics
and
are
evaluated
according
to
the
collection’s
index
system.
APIs.