4 ms·
The one feature that Python has that regularly makes me jealous when I'm using other languages is the generator / iterator mechanism. It's possible to write cod
by zmmmmm 13y ago
The one feature that Python has that regularly makes me jealous when I'm using other languages is the generator / iterator mechanism. It's possible to write code that is composable and modular in a functional way, and automatically scales to massive data with minimal memory use because the streaming mechanism is built in to the language at the ground level. I hope this is bringing the same to Java for real and that this is not just syntactic sugar on top of regular collection operations.
- ygra 13y agoFrom the docs: »•Possibly unbounded. While collections have a finite size, streams need not. Short-circuiting operations such as limit(n) or findFirst() can allow computations on infinite streams to complete in finite time.» So they can't just take collections here and pretend they're streams (but you can obtain streams from collections). But nice to see that the days of writing explicit loops just to filter a collection in Java are over. That being said, I still like Python's or C#'s syntactic enhancements to write generators/IEnumerables. The Spliterator in Java doesn't sound as easy to use and seems more aimed at low-level library code instead of user code. In the latter case you'd probably just get the stream from a collection again instead of creating it yourself. (You can apparently base it on a normal iterator, though, but the docs warn about it having bad performance in parallel scenarios.)