How to collect "some" items of a range in an array?
Renato
renato at athaydes.com
Mon Jan 6 19:30:27 UTC 2025
Is there any Phobos function that collects "some" items of a
range into an array/slice?
It's kind of embarrassing that I've been trying to find this for
hours now without success :(.
I think I know how to write this myself (though writing generic
stuff on ranges is not exactly straightforward), but surely there
is something for this and I am somehow missing it (even AI can't
help me)?
My use case is to parse a file format where a line is expected to
have 4 items. I am currently using `takeExactly(4)` but that
doesn't let me index on it, so I can only think of doing
inconvenient (and inefficient) stuff like `front, skip(1).front
...` to avoid having to write my own `toArray` :D. I couldn't
even find a method to take 1 item and advance the range! Am I
just looking at the entirely wrong places (std.range,
std.algorithm.iteration)??
More information about the Digitalmars-d-learn
mailing list