-
Notifications
You must be signed in to change notification settings - Fork 1
StdLib Generators Iterators
Function types for iteration and asynchronous programming.
| Type | Prototype Methods | Implemented |
|---|---|---|
| Generator | 3 | 0 (stubs) |
| GeneratorFunction | 1 | 0 (stub) |
| AsyncGenerator | 3 | 3 |
| AsyncGeneratorFunction | 1 | 0 (stub) |
| AsyncFunction | 1 | 1 |
| Iterator | 15 | 15 |
| AsyncIterator | ~15 | 0 |
Objects returned by generator functions.
Implementation Status: 0% (Stubs Only)
| Method | Status | Description |
|---|---|---|
next(value) |
Not Implemented | Throws NotImplementedException |
return(value) |
Not Implemented | Throws NotImplementedException |
throw(exception) |
Not Implemented | Throws NotImplementedException |
Note: Generator functions work via the IR execution system. The prototype methods are stubs because generators are handled internally by the execution engine, not through prototype method dispatch.
Constructor for generator functions.
Implementation Status: 0% (Stub)
| Method | Status | Description |
|---|---|---|
GeneratorFunction(...args, body) |
Not Implemented | Throws NotImplementedException |
Note: Cannot dynamically create generators from strings.
Objects returned by async generator functions.
Implementation Status: 100% Complete
| Method | Status | Description |
|---|---|---|
next(value) |
Implemented | Returns Promise for next value |
return(value) |
Implemented | Returns Promise, completes generator |
throw(exception) |
Implemented | Returns Promise, throws into generator |
Constructor for async generator functions.
Implementation Status: 0% (Stub)
| Method | Status | Description |
|---|---|---|
AsyncGeneratorFunction(...args, body) |
Not Implemented | Throws NotImplementedException |
Constructor for async functions.
Implementation Status: 100% Complete
| Method | Status | Description |
|---|---|---|
AsyncFunction(...args, body) |
Implemented | Creates async function from strings |
const asyncFn = new AsyncFunction('x', 'return await Promise.resolve(x * 2)');
await asyncFn(21); // 42Base prototype for all iterators with Iterator Helpers (TC39 proposal).
Implementation Status: 100% Complete
| Method | Status | Description |
|---|---|---|
[Symbol.iterator]() |
Implemented | Returns this
|
map(fn) |
Implemented | Lazy mapped iterator |
filter(fn) |
Implemented | Lazy filtered iterator |
take(n) |
Implemented | First n values |
drop(n) |
Implemented | Skip first n values |
flatMap(fn) |
Implemented | Map and flatten |
reduce(fn, init) |
Implemented | Reduce to single value |
toArray() |
Implemented | Collect to array |
forEach(fn) |
Implemented | Execute for each value |
some(fn) |
Implemented | Any match predicate |
every(fn) |
Implemented | All match predicate |
find(fn) |
Implemented | First matching value |
[Symbol.dispose]() |
Implemented | Close iterator |
| Method | Status | Description |
|---|---|---|
Iterator.from(iterable) |
Implemented | Create iterator from iterable |
Iterator.concat(...iterables) |
Implemented | Concatenate iterables |
const result = [1, 2, 3, 4, 5]
.values()
.filter(x => x % 2 === 0)
.map(x => x * 2)
.toArray();
// [4, 8]Base prototype for async iterators.
Implementation Status: 0% (Empty)
| Method | Status | Description |
|---|---|---|
[Symbol.asyncIterator]() |
Not Implemented | Should return this
|
map(fn) |
Not Implemented | Async mapped iterator |
filter(fn) |
Not Implemented | Async filtered iterator |
take(n) |
Not Implemented | First n values |
drop(n) |
Not Implemented | Skip first n |
flatMap(fn) |
Not Implemented | Async map and flatten |
reduce(fn, init) |
Not Implemented | Async reduce |
toArray() |
Not Implemented | Collect to array |
forEach(fn) |
Not Implemented | Async execute for each |
some(fn) |
Not Implemented | Async any match |
every(fn) |
Not Implemented | Async all match |
find(fn) |
Not Implemented | Async find first |
[Symbol.asyncDispose]() |
Not Implemented | Close async iterator |
Generators are executed via the IR system, not prototype methods:
flowchart LR
subgraph Creation
FN["function*"] --> IR["IR Plan"]
IR --> Invoker["SyncGeneratorInvoker"]
end
subgraph Execution
Call[".next()"] --> Runner["ExecutionPlanRunner"]
Runner --> Yield["YieldInstruction"]
Yield --> Pause["Pause + Return"]
end
Creation --> Execution
- Generator functions are compiled to IR
-
SyncGeneratorInvokermanages execution state -
YieldInstructionpauses and returns{ value, done } -
StoreResumeValuehandles.next(value),.return(),.throw()
| File | Purpose |
|---|---|
StdLib/Generator/GeneratorPrototype.cs |
Generator prototype (stubs) |
StdLib/GeneratorFunction/GeneratorFunctionConstructor.cs |
Constructor (stub) |
StdLib/AsyncGenerator/AsyncGeneratorPrototype.cs |
AsyncGenerator prototype |
StdLib/AsyncGeneratorFunction/AsyncGeneratorFunctionConstructor.cs |
Constructor (stub) |
StdLib/AsyncFunction/AsyncFunctionConstructor.cs |
AsyncFunction constructor |
StdLib/Iterator/IteratorPrototype.cs |
Iterator helpers |
StdLib/Iterator/IteratorConstructor.cs |
Iterator.from/concat |
StdLib/AsyncIterator/AsyncIteratorPrototype.cs |
AsyncIterator (empty) |
- Generators-and-Async - How generators and async work internally
- Iterator-Protocol - Iterator protocol details
- IR-Execution - How yield instructions work