How to iterate over range two items at a time
mipri
mipri at minimaltype.com
Mon Feb 17 05:07:11 UTC 2020
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
$ rdmd --eval '"hello world".chunks(2).each!writeln'
he
ll
o
wo
rl
d
$ rdmd --eval '"hello
world".chunks(2).map!"a.array.length".each!writeln'
2
2
2
2
2
1
Note the .array; each chunk is a range type.
$ rdmd --eval 'typeid("hello world".chunks(2).take(1)).writeln'
std.range.Take!(Chunks!string).Take
More information about the Digitalmars-d-learn
mailing list