Pass range to a function
Chris via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 27 14:16:03 PDT 2017
I'm using regex `matchAll`, and mapping it to get a sequence of
strings. I then want to pass that sequence to a function. What is
the general "sequence of strings" type declaration I'd need to
use?
In C#, it'd be `IEnumerable<string>`. I'd rather not do a
to-array on the sequence, if possible. (e.g. It'd be nice to just
pass the lazy sequence into my categorize function.)
What is the value of `???` in the following program:
```
import std.stdio, std.regex, std.string, std.algorithm.iteration;
auto regexToStrSeq(RegexMatch!string toks) {
return toks.map!(t => t[0].strip());
}
void categorize(??? toks) {
foreach (t; toks) {
writeln(t);
}
}
void main()
{
auto reg =
regex("[\\s,]*(~@|[\\[\\]{\\}()'`~^@]|\"(?:\\\\.|[^\\\\\"])*\"|;.*|[^\\s\\[\\]{}('\"`,;)]*)");
auto line = "(+ 1 (* 2 32))";
auto baz = matchAll(line, reg);
categorize(regexToStrSeq(baz).array);
}
```
More information about the Digitalmars-d-learn
mailing list