Help me write "saveAll"
Joshua Niehus
jm.niehus at gmail.com
Fri Dec 21 12:38:33 PST 2012
On Friday, 21 December 2012 at 17:01:14 UTC, monarch_dodra wrote:
> There are a lot of algorithms in std.algorithm that operate on
> "foo(Range, Needles...)(Range range, Needles needles)".
>
> Needles can be anything, in particular, either an "element" or
> a "range".
>
> The thing is that every now and then, you want to save the
> entirety of (the ranges) inside needles. EG, I want to be able
> to write:
> foo(range, needles.saveAll);
> [...snip...]
> Any thought on how do get this working?
> size_t r = startsWith!pred(haystack, needles.saveAll);
Sorry if im misunderstanding, but doesn't filter do this?
Example:
import std.stdio, std.algorithm, std.range;
void main() {
auto x = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10, 11, 12]
];
//haystack // needle //
needle
auto y = x.filter!(a => (a == [4, 5, 6] || a == [7, 8,
9])).array;
y.writeln;
}
More information about the Digitalmars-d-learn
mailing list