"Select" (Incremental Object)
IncrementalObject["Select"] [{e1,e2,…},crit]
creates an object that incrementally returns values for which crit[ei] is True.
IncrementalObject["Select"] [inc,crit]
creates an object that incrementally returns values from the incremental object or incremental function inc for which crit[ei] is True.
Details
- A "Select" incremental object is useful to filter values that come from the elements of an expression.
- The expression used as a source can be an object with any head, not necessarily List.
- The expression inc can be an expression with head IncrementalObject.
- The expression inc can be an object created by compiled code that uses IncrementalFunction.
- The following functions are also supported:
-
dsi===dsj True, if dsi equals dsj FullForm[ds] full form of ds InputForm[ds] input form of ds
Examples
open all close allBasic Examples (1)
Scope (5)
The expression argument does not have to be a list, just any compound expression:
obj = IncrementalObject["Select"][f[a[], a[1], a[1, 2]], Length[#] == 1&];
NextValue[obj]Only one argument met the criteria and so a failure object is returned:
NextValue[obj]An incremental object can be used in Table:
obj = IncrementalObject["Select"][Range[10], PrimeQ];
Table[e, {e, obj}]An incremental object can be used in Do:
obj = IncrementalObject["Select"][Range[10], PrimeQ];
Do[Echo[e], {e, obj}]"Select" incremental objects can use an IncrementalObject as a source:
iobj = IncrementalObject["Range"][10];Create an incremental object using the incremental object as a source:
obj = IncrementalObject["Select"][iobj, EvenQ]A list of all the values in the incremental object:
Table[e, {e, obj}]Selecting from incremental objects can use significantly less memory than working with lists of all the data:
MaxMemoryUsed[iobj = IncrementalObject["Range"][1000000];
obj = IncrementalObject["Select"][iobj, PrimeQ];Do[e, {e, obj}]]MaxMemoryUsed[rng = Range[1000000];
Select[rng, PrimeQ]]"Select" incremental objects can use an IncrementalFunction as a source:
ifun = FunctionCompile[IncrementalFunction[Function[{}, Do[IncrementalYield[i], {i, Infinity}]]]][];NextValue[ifun]Create an incremental object using the incremental function as a source:
obj = IncrementalObject["Select"][ifun, EvenQ]NextValue[obj]This underlying IncrementalFunction uses a limit of Infinity so the Table will not return:
TimeConstrained[Table[e, {e, obj}], 1]Properties & Relations (2)
InputForm (1)
InputForm returns the serialized contents of a "Select" incremental object:
InputForm[IncrementalObject["Select"][{1, 2, 3}, EvenQ]]This serialized form can be used to recreate the incremental object:
IncrementalObject["Select", {"Source" :> IncrementalObject["Identity", {"Source" :> {1, 2, 3}, "Position" :> 1}], "Function" :> EvenQ}]SameQ (1)
SameQ can be used to test whether two incremental objects contain the same sequence at the same position:
obj1 = IncrementalObject["Select"][{1, 2, 3, 4}, EvenQ];
obj2 = IncrementalObject["Select"][{1, 2, 3, 4}, EvenQ];
obj1 === obj2If one objects moves to the next value, the two objects are no longer the same:
NextValue[obj1];
obj1 === obj2Advancing the other object means that they are both now the same:
NextValue[obj2];
obj1 === obj2See Also
Related Guides
History
Introduced in 2026 (15.0)