3 ms·
I thought this syntax was weird too, but one cool thing is that you can ask for the index too for (items) |i, item| { } I guess Go does something simi
by chubot 5y ago
I thought this syntax was weird too, but one cool thing is that you can ask for the index too
for (items) |i, item| {
}
I guess Go does something similar, but it's a little weirder IMO because it has maps, while Zig doesn't.
I suppose it could have been
for i, item in items {
}
But I guess coming from Python that feels like tuple unpacking, which I don't think Zig has, but could make sense?
- ReactiveJelly 5y agoLua also has for i, v in ipairs (t) do -- i is the index, v is the value end Not getting the index in C++ easily was very frustrating. Often in C++ I fall back on C-style for-loops just because the functional stuff is hard to remember. In Rust it doesn't give you the index by default, but the `enumerate` adapter adds an index anywhere in a functional pipeline.