On Friday, 21 December 2012 at 20:38:34 UTC, Joshua Niehus wrote:
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;
}

I think there may be some misunderstanding. It's more like this;

//----
[1, 2, 3, 4].find(4, 7, [1, 3], [2, 3]);
//----
Here, as you can see, the 4 needles are:
4: Element
7: Element
[1, 3]: Range
[2, 3]: Range

In your example, you are just comparing elements: The elements themselves happen to be ranges, but that is irrelevant in the iteration scheme, they remain *elements* in the search.

In my example, Filter can't operate the Needle "[1, 3]", because it contains multiple elements.

Reply via email to