"Take" (Incremental Object)
IncrementalObject["Take"] [{e1,e2,…},n]
creates an object that incrementally returns at most n values.
IncrementalObject["Take"] [inc,n]
creates an object that incrementally returns at most n values from the incremental object or incremental function inc.
Details
- A "Take" incremental object is useful to limit the number of results that come from an incremental object.
- 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 (4)
The expression argument does not have to be a list, just any compound expression:
obj = IncrementalObject["Take"][f[a[], a[1]], 2];NextValue[obj]NextValue[obj]The limit has been reached, and a failure object is returned:
NextValue[obj]An incremental object can be used in Table:
obj = IncrementalObject["Take"][Range[10], 3];
Table[e, {e, obj}]An incremental object can be used in Do:
obj = IncrementalObject["Take"][Range[10], 3];
Do[Echo[e], {e, obj}]"Take" 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["Take"][iobj, 3]A list of all the values in the incremental object:
Table[e, {e, obj}]"Take" 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["Take"][ifun, 10]Even though the underlying IncrementalFunction uses a limit of Infinity the number of values is limited by the "Take" incremental:
Table[e, {e, obj}]As expected there are 10 of them:
Length[%]Properties & Relations (2)
InputForm (1)
InputForm returns the serialized contents of a "Take" incremental object:
InputForm[IncrementalObject["Take"][{1, 2, 3}, 3]]This serialized form can be used to recreate the incremental object:
IncrementalObject["Take", {"Source" :> IncrementalObject["Identity", {"Source" :> {1, 2, 3}, "Position" :> 1}], "Position" :> 1, "Start" :> 1, "End" :> 3, "Step" :> 1}]SameQ (1)
SameQ can be used to test whether two incremental objects contain the same sequence at the same position:
obj1 = IncrementalObject["Take"][Range[1000], 100];
obj2 = IncrementalObject["Take"][Range[1000], 100];
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)