IncrementalObject["name"][arg1,arg2,…]
creates an incremental object of the specified name.
IncrementalObject[name,data]
represents an incremental object that returns values one at a time.
IncrementalObject
IncrementalObject["name"][arg1,arg2,…]
creates an incremental object of the specified name.
IncrementalObject[name,data]
represents an incremental object that returns values one at a time.
Details
- Incremental objects are pre-built with the Wolfram Compiler.
- NextValue can be used with incremental objects to obtain values one at a time.
- When an incremental object is exhausted, the value returned is a failure object.
- Incremental objects can be used in functions that use iterators such as Table or Do.
- The values returned from incremental objects can be any Wolfram Language expression.
- Incremental objects that take a source can use expressions, other incremental objects and incremental functions.
- Certain Wolfram Language functions have incremental object forms.
- "name" can take the following forms:
-
"Identity" returns values that are the elements of an expression "Range" returns numerical values as in Range "Select" returns values that pass a criteria as in Select "Take" returns a fixed number of values as in Take "Map" returns values from applying a function as in Map "FoldList" returns values from repeated application of a function as in FoldList "Permutations" returns values that are permutations of a list as in Permutations "Subsets" returns values that are subsets of a list as in Subsets "Tuples" returns values that are tuples of elements from a list as in Tuples
Examples
open all close allBasic Examples (2)
obj = IncrementalObject["Identity"][{1, 2}]Return the first value from the incremental object:
NextValue[obj]NextValue[obj]When no more values are available, a failure object is returned:
NextValue[obj]When an incremental object is used as the source for Table, it returns all remaining elements:
obj = IncrementalObject["Identity"][{1, 2, 3}];
Table[e, {e, obj}]Create an incremental object and return a value:
obj = IncrementalObject["Identity"][{1, 2, 3}];
NextValue[obj]Table returns only those remaining elements:
Table[e, {e, obj}]An incremental object can be used as the source for Do:
obj = IncrementalObject["Identity"][{a, b, c}];
Do[Echo@e, {e, obj}]Scope (5)
The values returned from incremental objects can be any Wolfram Language expression:
obj = IncrementalObject["Identity"][{f[1], f[2], f[3]}];
Table[e, {e, obj}]Incremental objects can be built from combinatorial sources such as permutations:
obj = IncrementalObject["Permutations"][{1, 2, 3}]The first value in the permutation:
NextValue[obj]Table[e, {e, obj}]Working incrementally generates results one at a time; which uses less memory:
MaxMemoryUsed[Do[e, {e, IncrementalObject["Permutations"][{1, 2, 3, 4, 5, 6, 7, 8}]}]]A related operation with the Permutations function generates all the permutations at once and uses much more memory:
MaxMemoryUsed[Do[e, {e, Permutations[{1, 2, 3, 4, 5, 6, 7, 8}]}]]It would not be possible to create all the permutations for as many objects as this:
obj = IncrementalObject["Permutations"][Range[100]];
NextValue[obj]The next 100000 elements can be stepped over:
Do[NextValue[obj], {100000}];
NextValue[obj]An incremental object that returns successive accumulations:
obj = IncrementalObject["FoldList"][Plus, 0, Range[10]];
NextValue[obj]Table[e, {e, obj}]An incremental object can be nested inside another incremental object. Using an incremental range like this allows successive integers to be tested:
obj = IncrementalObject["FoldList"][Plus, 0, IncrementalObject["Range"][2^50]];Table[NextValue[obj], {100}]Incremental objects are stateful and are not cloned when used as the source for other incremental objects:
obj = IncrementalObject["Range"][2^20];
NextValue[obj]Use an incremental object as the source for another:
obj1 = IncrementalObject["Select"][obj, PrimeQ];
Table[NextValue[obj1], 10]The source incremental object has been modified:
NextValue[obj]Incremental functions can also be used as a source for an incremental object:
fibComp = FunctionCompile[IncrementalFunction[Function[{}, Module[{a = TypeHint[0, "InertExpression"], b = TypeHint[1, "InertExpression"]}, Do[IncrementalYield[a];{a, b} = {b, a + b};, {Infinity}]]]]]The first 10 Fibonacci numbers:
ds = fibComp[];
Table[NextValue[ds], {10}]Create an incremental object that uses the incremental function as a source:
obj = IncrementalObject["Select"][fibComp[], EvenQ]The first 40 even Fibonacci numbers:
Table[NextValue[obj], {40}]Neat Examples (1)
Incremental Fibonacci Numbers (1)
An incremental object that returns Fibonacci numbers:
obj = IncrementalObject["Map"][First, IncrementalObject["FoldList"][Module[{a, b}, {a, b} = #1;{b, a + b}]&, {0, 1}, IncrementalObject["Range"][10^6]]]Skip over 1000 values and return the one after that:
Do[NextValue[obj], {1000}];NextValue[obj]The same computation carried out with the Fibonacci function:
Fibonacci[1001]See Also
Related Guides
History
Text
Wolfram Research (2026), IncrementalObject, Wolfram Language function, https://reference.wolfram.com/language/ref/IncrementalObject.html.
CMS
Wolfram Language. 2026. "IncrementalObject." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/IncrementalObject.html.
APA
Wolfram Language. (2026). IncrementalObject. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/IncrementalObject.html
BibTeX
@misc{reference.wolfram_2026_incrementalobject, author="Wolfram Research", title="{IncrementalObject}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/IncrementalObject.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_incrementalobject, organization={Wolfram Research}, title={IncrementalObject}, year={2026}, url={https://reference.wolfram.com/language/ref/IncrementalObject.html}, note=[Accessed: 12-June-2026]}