nustack
ReferenceStd

nu.std.itertools

Gap-fill over Nu core: members core already covers (map/filter/zip/sorted/enumerate/reversed/sums) are not repeated. Every member is a hand-written StreamQuery atom except tee.

from nu.std.itertools import chain, islice, count

Infinite sources

NameSortSignatureEffectMeaning
countStreamQuerycount(start=0, step=1)pureunbounded arithmetic stream; bound with islice
cycleStreamQuerycycle(iterable)purerepeat a source forever
repeatStreamQueryrepeat(elem, times=None)pureyield elem times times, or forever

Pure combinators

NameSortSignatureEffectMeaning
chainStreamQuerychain(*iterables)pureconcatenate sources end to end
chain_from_iterableStreamQuerychain_from_iterable(iterable)pureflatten an iterable of iterables one level
isliceStreamQueryislice(iterable, *args)purelazy slice (stop | start,stop | start,stop,step)
compressStreamQuerycompress(data, selectors)purekeep data where selectors is truthy
pairwiseStreamQuerypairwise(iterable)pureoverlapping consecutive pairs
batchedStreamQuerybatched(iterable, n)puretuples of up to n items
zip_longestStreamQueryzip_longest(*iterables, fillvalue=None)purezip to the longest, padding short sources
productStreamQueryproduct(*iterables, repeat=1)purecartesian product
permutationsStreamQuerypermutations(iterable, r=None)purer-length ordered arrangements
combinationsStreamQuerycombinations(iterable, r)purer-length sorted subsequences
combinations_with_replacementStreamQuerycombinations_with_replacement(iterable, r)purer-length subsequences allowing repeats

Higher-order

NameSortSignatureEffectMeaning
takewhileStreamQuerytakewhile(predicate, iterable)pureyield while predicate holds, stop at the first falsy
dropwhileStreamQuerydropwhile(predicate, iterable)pureskip while predicate holds, then yield the rest
filterfalseStreamQueryfilterfalse(predicate, iterable)purekeep items where predicate is falsy
accumulateStreamQueryaccumulate(iterable, func=None)purerunning accumulation (sum by default, or a Nu term over acc/item)
starmapStreamQuerystarmap(function, iterable)pureapply function to unpacked tuple items
groupbyStreamQuerygroupby(iterable, key=None)puregroup consecutive items by key -> (key, tuple(group)) pairs

tee

NameSortSignatureEffectMeaning
teeScalarQuerytee(iterable, n=2)puresplit into n independent iterators -> Any holding a tuple (not a stream)

On this page