Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101792 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58972 invoked from network); 6 Feb 2018 20:18:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Feb 2018 20:18:13 -0000 Authentication-Results: pb1.pair.com smtp.mail=tendoaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tendoaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.193 as permitted sender) X-PHP-List-Original-Sender: tendoaki@gmail.com X-Host-Fingerprint: 209.85.161.193 mail-yw0-f193.google.com Received: from [209.85.161.193] ([209.85.161.193:46639] helo=mail-yw0-f193.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EC/08-49805-28D0A7A5 for ; Tue, 06 Feb 2018 15:18:11 -0500 Received: by mail-yw0-f193.google.com with SMTP id c78so2255308ywb.13 for ; Tue, 06 Feb 2018 12:18:10 -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=ESIB426DPYOYz3lvqAfTNDlIMVIPoFyUV9s7nTlu9sA=; b=BBwJKInYx72zvaHIPvFTonGb9SN55gUWpVYFpJrw9SJ/T22gedYMCbf+rd6fS/k2od +lp5Qah5cQzwOxJojgdAK6Cl2cnBvZp5ra67SuUS1rLavRjryXmq0glOPdW9Tdcx60ob +ORz8jXD0rw/bqzKG/dAumfoHWlPHwItdMLf7qZKaofN2JHPgzO0kcFM4Dczj2inf4fC 6fJYOygPcd4Ex1OtGYIGAHpOr3r+efwNbZqrAiewGyI76P5S0P8sJw/GnhhuGGVmohzZ 5m3UjA7fO7aJn9EDc0/971zQQy3YQSnJ02ZbnSAnYTZk+DNOoymnUUdLJpHfxugwFuh1 6ZRQ== 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=ESIB426DPYOYz3lvqAfTNDlIMVIPoFyUV9s7nTlu9sA=; b=jejjVd8pUxsDGHRHvTviRedjIqcirYmSRMv17J1aOtIpogQuOjpkwr2gd3/6txQKj3 Lr7GErx6j0nXHaFEpkUjh57HyJXz0TSshu6a7M0gDJDQ7zHZToxbS56UFHsrcL1Zepjo G1Q5a5YFnXrFCnUGSQ+lVjUqmj34JthyWJPrxQB57U8amK0W7qJKH8aaNKACdvrRBSHx 4hdyVqB75nkyZArOn7J7YY5x/n5P+XKqRJ9G30F6i6TCsZUN5W71gubnG7Ol//OZreQO JsJxoXSPiLKsYVmitoIMyAypxpTQ/VS3nnginjSs7dQZm67IcuKL9Tlg23s1nhs5zN39 gPaA== X-Gm-Message-State: APf1xPBhT24NmW+QtgbzLI44cmmBu+Bxh8Iq9kToikSWXESjg3Ea0jOU fIT21MpSbnquv8qyGIGE2iodZPKEHQbfaPGfivw= X-Google-Smtp-Source: AH8x224+b3ECgfOxwLNBCPyzRnccA9Zpe+5hDsjxmYK8YLKhwNryVkNv7GqOv14A08CObGbSVrF0KPP+6HV7Jgp5UIE= X-Received: by 10.129.55.209 with SMTP id e200mr2293829ywa.306.1517948288088; Tue, 06 Feb 2018 12:18:08 -0800 (PST) MIME-Version: 1.0 Received: by 10.37.206.137 with HTTP; Tue, 6 Feb 2018 12:18:07 -0800 (PST) In-Reply-To: References: <4026445.Wp3pesFrPl@vulcan> <28100667.gh41XH5Xuc@vulcan> Date: Tue, 6 Feb 2018 14:18:07 -0600 Message-ID: To: internals Content-Type: multipart/alternative; boundary="001a1144016c7fbe9d056490e0d3" Subject: Re: [PHP-DEV][RFC][DISCUSSION] Collection Inspection From: tendoaki@gmail.com (Michael Morris) --001a1144016c7fbe9d056490e0d3 Content-Type: text/plain; charset="UTF-8" On Tue, Jan 30, 2018 at 2:24 PM, Levi Morrison wrote: > On Tue, Jan 30, 2018 at 11:13 AM, Larry Garfield > wrote: > > On Monday, January 29, 2018 6:46:10 PM CST Michael Morris wrote: > >> 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. > > > > I don't recall doing so in this thread, but I most likely have on some > other > > issue. It's the sort of comment that I would make. :-) > > > > However, that's for a very commonly used function where just inlining it > is > > prohibitive. As you've demonstrated below, this functionality is easily > a one > > liner, and it's a one-liner in an assert statement most likely. > > > >> 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. > > > > Personally I think that's fine, and doesn't need a language-level utility > > function to wrap it any further. > > > > (Yes, that's a subjective metric. So are most statements about what > > should[n't] be included in the language itself. Others are welcome to > > disagree, but this falls below my threshold of necessity.) > > > > --Larry Garfield > > > I agree with this sentiment from Larry. However I do think there is a > function we could add: > > function every(callable $predicate, traversable $input): bool { > foreach ($input as $value) { > if (!$predicate($value)) { > return false; > } > } > return true; > } > > In which case the code would become: > > assert(every('is_string', $input)); > > Of course, when passing a traversable the caller must to be careful as > it will be consumed. If they don't want that to happen they can > convert it to an array (possibly with iterator_to_array). > > The reason this "every" function is better than "array_test" is > because it is more general and works with more things than just types. > The name "every" I borrowed from Clojure, but it's known by many > names; in Java it is known as "allMatch". > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > I'm fine with this - I just want the inspector to be part of the language so that a hidden dependency isn't required. --001a1144016c7fbe9d056490e0d3--