Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101729 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79735 invoked from network); 30 Jan 2018 00:46:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jan 2018 00:46:15 -0000 Authentication-Results: pb1.pair.com header.from=tendoaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tendoaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.173 as permitted sender) X-PHP-List-Original-Sender: tendoaki@gmail.com X-Host-Fingerprint: 209.85.161.173 mail-yw0-f173.google.com Received: from [209.85.161.173] ([209.85.161.173:35117] helo=mail-yw0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8F/5F-24062-550CF6A5 for ; Mon, 29 Jan 2018 19:46:15 -0500 Received: by mail-yw0-f173.google.com with SMTP id u21so3469561ywc.2 for ; Mon, 29 Jan 2018 16:46:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=RNW4aom01kxLjqb6wk1H3lbvmD/YWrZgKr/2kBPeYZQ=; b=jxG+l78ygElm1252jSE0nlZANkNI77ShRyXn71hP08wzexMuejLKd5YVMvwWNNOKgT 58Hm2soMWgrXRdDX8ypfnsqlhGToYjACyEd6V0rY7Yi7tMCpEUvl6oZscATCBD8qbw7z +6bNr5n2T1CeLeAOCwibBY3kDPPb3h0QfvQ25vI1z2FP267zko0pDvEKHdsp0advBUBO oTT3AB6Fml+j+T9jjEOWQ5Si5PzLajWtdG8T27iNRnvaDAh6kdAoxqZFmA+YQgpBfdE4 IY7tKxUmn4KDVcVvos4qb6/n0277o2F+Xms76d3vI7S1qIim8bUzmVclBCv5CiFgSDKt ThUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=RNW4aom01kxLjqb6wk1H3lbvmD/YWrZgKr/2kBPeYZQ=; b=ZUJ0AsqMEYwKbE3HImdstGqfOvaYcFVZOxccTvlKAfK/xWI8/gML9oaQXgKyxFYfUN TZEVkBhtA+GZuMRWqHS8mLjlxejVnYHd9j2rIU+REtj1wHUPn2lNDavY6RXsqO4DU5if UGH9BTI0JEfX7xoOSh+GdcEMVk//JAjsPybBIma1Fb6Hnq/kaBhMIpRvSd0ixI2eMiQG 8m8GvPMLuO+Aa+6fHfzokdiHk7Q9LRfuZB5YprMBJo0wzBze0qAAAzBAqSYFTBvGhrog vZzVG6kk1tGRJTBUoK3FQDt9EsnwzKd8/DUXuhbQOp/iAvA1vKjVEECtWed9UcLOc5LC 6nbg== X-Gm-Message-State: AKwxytdd+lq+V/c9vyRZY4+HXtOJfUP8f61UEtXKCcyqHDWw+UJo9UIp jTAuvNPn2/hfLyeYuChCDKLW/dMqJpphlhyO/G79VA== X-Google-Smtp-Source: AH8x224x38udFw+Rlooiz+Yr8c2N8cbBHmRTgUG6sa7thSsnq2k3ZxsWABVMU0MBLcSC+9zTfjDpuw3GxFZWNhTjUfY= X-Received: by 10.129.145.84 with SMTP id i81mr18903975ywg.480.1517273170468; Mon, 29 Jan 2018 16:46:10 -0800 (PST) MIME-Version: 1.0 Received: by 10.37.189.16 with HTTP; Mon, 29 Jan 2018 16:46:10 -0800 (PST) In-Reply-To: <4026445.Wp3pesFrPl@vulcan> References: <4026445.Wp3pesFrPl@vulcan> Date: Mon, 29 Jan 2018 18:46:10 -0600 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="94eb2c0942145a64070563f3b018" Subject: Re: [PHP-DEV][RFC][DISCUSSION] Collection Inspection From: tendoaki@gmail.com (Michael Morris) --94eb2c0942145a64070563f3b018 Content-Type: text/plain; charset="UTF-8" On Mon, Jan 29, 2018 at 6:16 PM, Larry Garfield 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 --94eb2c0942145a64070563f3b018--