3 ms·
> 3. Iterators. Never seen a language do them so well with so little overhead. The focus on zero-cost abstractions really shines here. Try some D, maybe? :)
by nialv7 10y ago
> 3. Iterators. Never seen a language do them so well with so little overhead. The focus on zero-cost abstractions really shines here.
Try some D, maybe? :)
- vvanders 10y agoHaven't had a chance to play with D yet but a quick perusal shows quite a few things missing from their iterator lib(zip, enumerate, cycle, collect). I probably just need to spend some time with it at some point. That said the examples look much close to Rust than C++11(seriously did they think through how painful std::transform() is with all the begin/end pairs?). One thing that not a lot of people know is you can iterate over a Result<T,E> and collect::<Result<Vec<T>, E>>() which is a really elegant way to bail on a single error or get a collection of values.
- nialv7 10y agoD does have zip, enumerate, cycle (https://dlang.org/phobos/std_range.html https://dlang.org/phobos/std_range.html). It doesn't have a universal collect like Rust, but you can create arrays from ranges using array(). And if the target container/collection type is an OutputRange, you can use the put()(https://dlang.org/phobos/std_range_primitives.html#.put https://dlang.org/phobos/std_range_primitives.html#.put) function to create collections from ranges.