On Mon, Jan 29, 2018 at 6:16 PM, Larry Garfield <la...@garfieldtech.com> wrote: > > > Really, these functions would be useful only on arrays, period. To allow > them > on anything else is just dangerous, and on other iterables there are > better, > more robust approaches (as discussed elsewhere in this thread). > > As you've demonstrated they're also quite compact and effective to do in > user- > space, so unless there's a massive performance difference of moving them > to C > they don't seem all that appropriate to add to the language directly. > > --Larry Garfield >
Didn't you personally raise the issue of hard dependencies doing this sort of functionality creates? Implementable in userland or not, this is pretty low level functionality. Hmm.. If limited to arrays only then array_filter with count is pretty close to what we want. assert(count(array_filter($a, is_string)) === count($a)); That's not optimal though - granted assert code doesn't *have* to be optimal, but that's still a wordy construction. So what about this function bool array_test(array $array [, callable $callback [, mixed $flag = 0]]) Iterates over $array, passing the value of each element to $callback. If the callback returns true for all elements the array_test returns true, otherwise it returns false. It is not guaranteed to iterate over the entire array - it stops when the first false result is returned by the callback. Flags are the same as array_filter. So... assert( array_test($a, 'is_string'), TypeError); assert( array_test($a, function($v) { return $v instanceof SomeClass; }), TypeError); Not what I came into the thread looking for, but it's not bad. s