3 ms·
Haven'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
by vvanders 10y ago
Haven'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.