On Monday, 17 February 2020 at 05:04:02 UTC, Adnan wrote:
What is the equivalent of Rust's chunks_exact()[1] method in D? I want to iterate over a spitted string two chunks at a time.


[1] https://doc.rust-lang.org/beta/std/primitive.slice.html#method.chunks_exact

And, after actually reading the Rust doc, I see that you want
to iterate over a string two chars at a time while discarding
any remaining 1-length chunk.

There isn't an equivalent of that.

A quick one is

auto chunks_exact(R)(R r, size_t n) {
    return r.take(r.length - r.length%n).chunks(n);
}

but to get the exact same behavior you'll want to return a
range type that stores the final chunk.

Reply via email to