API reference¶
The supported application-facing API consists of rangeslib.Range,
rangeslib.ranges, and rangeslib.views. Modules beginning with an
underscore are private implementation details.
Core container¶
- class rangeslib.Range(*args)¶
Bases:
UserList,GenericA list-backed, typed container used as the library’s pipeline value.
Rangeis eager: constructing or applying an adaptor stores the result immediately. Construction uses positional values, soRange(1, 2, 3)contains three elements. Standard list-like operations preserveRangeas the result type.- copy()¶
Return a shallow
Rangecopy without nesting the source range.- Return type:
Range[TypeVar(T)]
- is_empty()¶
Return
Truewhen the range has no elements.- Return type:
bool
Generator facade¶
- rangeslib.ranges.indices(count)¶
Create zero-based indices up to, but excluding,
count.- Return type:
Range[int]
- rangeslib.ranges.iota(start, end)¶
Create integers from
startup to, but excluding,end.- Return type:
Range[int]
View facade¶
- rangeslib.views.adjacent(width=2)¶
Return overlapping tuple windows of
widthvalues.- Return type:
_AdjacentView
- rangeslib.views.adjacent_transform(func, width=2)¶
Call
funcfor each overlapping window ofwidthvalues.- Return type:
AdjacentTransform[Any,TypeVar(OutputT)]
- rangeslib.views.all()¶
Materialize an existing iterable as an eager
Range.This mirrors C++
views::allat the public API level. Python does not expose borrowed-range or view ownership categories, so this implementation always returns a reusable, materializedRange.- Return type:
_TypePreservingView
- rangeslib.views.cartesian_product(*iterables)¶
Return the Cartesian product of the input and configured iterables.
- Overloads:
→ _CartesianProductView0
iterable (Iterable[OtherT]) → _CartesianProductView1[OtherT]
first (Iterable[OtherT]), second (Iterable[ThirdT]) → _CartesianProductView2[OtherT, ThirdT]
iterables (Iterable[Any]) → _VariadicCartesianProductView
Runtime calls may provide more than two configured iterables; precise public typing is provided for zero, one, and two configured iterables. Larger calls use a tuple-of-
Anyfallback type.
- rangeslib.views.chunk(size)¶
Partition the input into non-overlapping
Rangechunks.sizemust be positive. The final chunk may contain fewer values.- Return type:
_ChunkView
- rangeslib.views.chunk_by(predicate)¶
Split whenever
predicate(previous, current)returnsFalse.- Return type:
ChunkBy[TypeVar(InputT)]
- rangeslib.views.concat(*iterables)¶
Append configured iterables after the pipeline input.
- Return type:
Concat[TypeVar(InputT)]
- rangeslib.views.counted(count)¶
Consume at most
countvalues from the current iterator position.Unlike
take,counteddoes not first materialize the entire input.countmust be non-negative.- Return type:
_TypePreservingView
- rangeslib.views.drop(count)¶
Drop values using Python slice-start semantics.
Negative counts behave like
list(iterable)[count:]and therefore require complete input materialization.- Return type:
_TypePreservingView
- rangeslib.views.drop_while(predicate)¶
Alias for
dropwhile()using C++-style word separation.- Return type:
DropWhile[TypeVar(InputT)]
- rangeslib.views.dropwhile(predicate)¶
Drop initial values while
predicateremainsTrue.- Return type:
DropWhile[TypeVar(InputT)]
- rangeslib.views.elements(index)¶
Project integer-indexed field
indexfrom every input value.- Return type:
Elements[Any]
- rangeslib.views.enumerate(start=0)¶
Pair each input value with a sequential integer index.
- Return type:
_EnumerateView
- rangeslib.views.filter(predicate)¶
Keep values for which
predicatereturnsTrue.- Return type:
Filter[TypeVar(InputT)]
- rangeslib.views.join()¶
Flatten one level of nested iterables.
- Return type:
_JoinView
- rangeslib.views.join_with(separator)¶
Flatten nested iterables with
separatorinserted between them.- Return type:
JoinWith[TypeVar(InputT)]
- rangeslib.views.keys()¶
Project field
0from every tuple-like input value.- Return type:
_KeysView
- rangeslib.views.pairwise()¶
Return overlapping two-value tuples.
- Return type:
_PairwiseView
- rangeslib.views.pairwise_transform(func)¶
Call a binary
funcfor each adjacent pair.- Return type:
PairwiseTransform[TypeVar(InputT),TypeVar(OutputT)]
- rangeslib.views.reverse()¶
Reverse all input values and return an eager
Range.- Return type:
_TypePreservingView
- rangeslib.views.slide(width)¶
Return overlapping
Rangewindows of exactlywidthvalues.- Return type:
_ChunkView
- rangeslib.views.split(separator)¶
Split input wherever the separator pattern occurs.
Empty chunks are preserved. An empty separator raises
ValueErrorwhen the adaptor is applied.- Return type:
Split[TypeVar(InputT)]
- rangeslib.views.stride(step)¶
Select every
step-th value, starting with the first.stepmust be positive.- Return type:
_TypePreservingView
- rangeslib.views.take(count)¶
Take values using Python slice-stop semantics.
Positive and zero counts select a prefix. Negative counts behave like
list(iterable)[:count]and therefore require complete input materialization.- Return type:
_TypePreservingView
- rangeslib.views.take_while(predicate)¶
Alias for
takewhile()using C++-style word separation.- Return type:
TakeWhile[TypeVar(InputT)]
- rangeslib.views.takewhile(predicate)¶
Take initial values while
predicateremainsTrue.- Return type:
TakeWhile[TypeVar(InputT)]
- rangeslib.views.to(target_type, /)¶
Convert the pipeline input with
target_type.- Overloads:
target_type (type[str]) → To[str, str]
target_type (Callable[[Iterable[InputT]], OutputT]) → To[InputT, OutputT]
tois the only public adaptor that does not necessarily returnRange; it returns exactly what the supplied callable produces. Passing the built-instrjoins string elements without a separator.
- rangeslib.views.transform(func)¶
Map every input value through
func.- Return type:
Transform[TypeVar(InputT),TypeVar(OutputT)]
- rangeslib.views.values()¶
Project field
1from every tuple-like input value.- Return type:
_ValuesView
- rangeslib.views.zip(*iterables)¶
Zip the pipeline input with configured iterables to the shortest length.
- Overloads:
→ _ZipView0
iterable (Iterable[OtherT]) → _ZipView1[OtherT]
first (Iterable[OtherT]), second (Iterable[ThirdT]) → _ZipView2[OtherT, ThirdT]
iterables (Iterable[Any]) → _VariadicZipView
Runtime calls may provide more than two configured iterables; precise public typing is provided for zero, one, and two configured iterables. Larger calls use a tuple-of-
Anyfallback type.
- rangeslib.views.zip_transform(func, *iterables)¶
Zip corresponding values and call
funcfor each group.- Return type:
ZipTransform[TypeVar(OutputT)]