The predicate. Optimization: any!"a" has accelerated specialization for slices created with mir.ndslice.topology.bitwise, mir.ndslice.allocation.bitSlice.
Ranges and arrays
import std.range : iota; // 0 1 2 3 4 5 auto r = iota(6); assert(r.any!"a == 3"); assert(!r.any!"a == 6");
import mir.ndslice.topology : iota; // 0 1 2 // 3 4 5 auto sl = iota(2, 3); assert(sl.any!"a == 3"); assert(!sl.any!"a == 6");
Multiple slices
import mir.ndslice.topology : iota; // 0 1 2 // 3 4 5 auto a = iota(2, 3); // 10 11 12 // 13 14 15 auto b = iota([2, 3], 10); assert(any!((a, b) => a * b == 39)(a, b));
Zipped slices
import mir.ndslice.topology : iota, zip; // 0 1 2 // 3 4 5 auto a = iota(2, 3); // 10 11 12 // 13 14 15 auto b = iota([2, 3], 10); // slices must have the same strides assert(zip!true(a, b).any!"a.a * a.b == 39");
Mutation on-the-fly
import mir.ndslice.allocation : slice; import mir.ndslice.topology : as, iota; // 0 1 2 // 3 4 5 auto sl = iota(2, 3).as!double.slice; static bool pred(T)(ref T a) { if (a == 5) return true; a = 8; return false; } assert(sl.any!pred); // sl was changed assert(sl == [[8, 8, 8], [8, 8, 5]]);
Like find, but only returns whether or not the search was successful.