4 ms·
To be fair, the way IEnumerable<T> works is more of a historical fact. The underlying type systems allows you to implement the same monomorphized iterators lik
by neonsunset 2y ago
To be fair, the way IEnumerable<T> works is more of a historical fact.
The underlying type systems allows you to implement the same monomorphized iterators like in Rust, which some third-party libraries do.
The main limitations are at the language level - the lack of associated types and high order functions being opaque means that for nested iterators you may end up writing unwieldy generic signature by hand, and instead of lambda - manually writing a value-delegate-like struct. In a brighter tomorrow, it will be a matter of the language doing so on your behalf, but in either case there is nothing preventing another guest language or even C# itself in the future having identical iterator abstraction implementation to Rust within the existing type system (unlikely to happen in C# as-is because it would be a huge breaking change, the compiler is getting better at inlining and devirtualization so in the simpler cases it may become not needed).