This cannot be made completely type safe ... but assuming the array does contain elements of the correct types, since they must appear in a Tuple of type Where , the following function will do the trick:
Tuple<Anything, Anything, Anything> typedTuple({Anything+} array) { if (exists second = array.rest.first) { return Tuple(array.first, typedTuple({ second }.chain(array.rest.rest))); } else { return Tuple(array.first, []); } }
And the application is applied as:
Result apply<Result, Where>( [Anything+] array, Callable<Result, Where> fun) given Where satisfies Anything[] { value tuple = typedTuple(array); assert(is Where tuple); return fun(*tuple); }
source share