using std.algorithm to find intersection of DateTime[][] arg

deed via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 10 04:58:06 PDT 2015


On Wednesday, 9 September 2015 at 20:28:35 UTC, Laeeth Isharc 
wrote:
> I have a DateTime[][] arg ...
> I would like to find the intersection of the dates.

A suggestion:

auto minLength      = arg.map!(a => a.length).reduce!min;
auto minIdx         = arg.map!(a => 
a.length).countUntil(minLength);
auto intersection   = arg[minIdx].filter!(e => 
chain(arg[0..minIdx], arg[minIdx..$]).all!(a => 
a.assumeSorted.contains(e)));

reduce with setIntersection seems the most straightforward, but 
needs array AFAIK, i.e.:

auto intersection =
//reduce!((r, x) => setIntersection(r, x))(arg);      // doesn't 
work
   reduce!((r, x) => setIntersection(r, x).array)(arg);// does, 
but with array



More information about the Digitalmars-d-learn mailing list