Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62351 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24963 invoked from network); 21 Aug 2012 19:26:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Aug 2012 19:26:22 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 64.22.89.133 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 64.22.89.133 oxmail.registrar-servers.com Received: from [64.22.89.133] ([64.22.89.133:42868] helo=oxmail.registrar-servers.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C0/E2-10139-DD0E3305 for ; Tue, 21 Aug 2012 15:26:21 -0400 Received: from [192.168.0.200] (5ad3285b.bb.sky.com [90.211.40.91]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by oxmail.registrar-servers.com (Postfix) with ESMTPSA id D0611758070; Tue, 21 Aug 2012 15:26:16 -0400 (EDT) Message-ID: <5033E0BC.8040507@ajf.me> Date: Tue, 21 Aug 2012 20:25:48 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: Yasuo Ohgaki CC: Tjerk Anne Meesters , Rasmus Schultz , internals@lists.php.net References: <502EB667.1020602@lerdorf.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] re: removing an item from an array From: ajf@ajf.me (Andrew Faulds) On 21/08/12 10:36, Yasuo Ohgaki wrote: > Hi > > 2012/8/21 Tjerk Anne Meesters : >> On Tue, Aug 21, 2012 at 10:31 AM, Rasmus Schultz wrote: >> >>> Thank you, but this isn't really anything like what I had in mind. >>> >>> What I had in mind is more like set-semantics for arrays, e.g. designed to >>> work with sets of distinct values/objects. >>> >>> Since I do not have permission to write on the wiki, I posted an initial >>> draft here: >>> >>> https://gist.github.com/321ad9b4b8c4e1713488 >> >> Just an idea, since array_delete() may remove multiple values, I would >> change the return value to (int) and return how many elements were removed >> from the array. > Int would be better and callable should be accepted like array_walk(). > It's better to have array_delete_recursive(), too. > I updated the page. Callable? What? This is to remove a single value, like a set. If you want to remove based on a function, array_walk() is always available. And allowing a callable would prevent you from removing closures or strings! D: > > array_add() needs more discussion. > What we should do with array value, accept callable or not, etc. Why accept a callable? I don't think it needs more discussion, I can't see how it could be made any better than it currently is. > Regards, > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net > > > >> >>> >>> >>> On Mon, Aug 20, 2012 at 10:10 PM, Yasuo Ohgaki wrote: >>> >>>> Hi, >>>> >>>> 2012/8/21 Rasmus Schultz : >>>>> I have a login (mindplay) but I do not have permission to post or edit >>>>> anything on the wiki... >>>> I've created RFC for this >>>> >>>> https://wiki.php.net/rfc/array_delete >>>> >>>> Get wiki account and finish discussion. >>>> I may write patch for this with my spare time, but >>>> it may take while to find time. I suggest write patch >>>> and send pull request. >>>> >>>> Regards, >>>> >>>> -- >>>> Yasuo Ohgaki >>>> yohgaki@ohgaki.net >>>> >>>>> On Mon, Aug 20, 2012 at 8:01 PM, Will Fitch wrote: >>>>> >>>>>> Please let this die until someone is serious enough to come up with an >>>>>> rfc. This has been nothing but counterproductive arguing. If someone >>>> feels >>>>>> strongly about it, write an rfc then we can discuss? >>>>>> On Aug 20, 2012 7:53 PM, "Yasuo Ohgaki" wrote: >>>>>> >>>>>>> Hi, >>>>>>> >>>>>>> 2012/8/21 Herman Radtke : >>>>>>>>>> May be we should have something like >>>>>>>>>>> array_delete_if($array, function($v, $k=null) { if ($v == 300) >>>>>>> return >>>>>>>>>>> true; }) >>>>>>>>>> So array_filter? >>>>>>>>> I'll use it or like for deleting, but the point of this thread is >>>>>>>>> "intuitive function for deleting element(s)" >>>>>>>>> >>>>>>>>> array_delete($array, $value|callable) >>>>>>>>> >>>>>>>>> would be nicer for users, perhaps. >>>>>>>> >>>>>>>> You are basically asking to alias array_filter with "array_delete". >>>>>>> That is >>>>>>>> a very slippery slope. I think array_filter is very a very obvious >>>>>>> choice to >>>>>>>> remove something from an array. The "filter" function/method is >>>> common >>>>>>> in >>>>>>>> functional languages (and functional frameworks like Underscore). >>>>>>>> >>>>>>>> These are things developers just need to learn as part of >>>> development. >>>>>>>> Really, this is entire thread should be on stack overflow, not >>>>>>> internals. >>>>>>> >>>>>>> I guess you haven't read later post. >>>>>>> >>>>>>> You've also made a novice mistake. >>>>>>> array_filter() DO NOT delete elements, but creates new array. >>>>>>> array_delete() is another form of array_walk(), not array_filter(). >>>>>>> See my posts. >>>>>>> >>>>>>> Having a API for dedicated task is good thing. >>>>>>> Who would argue array_pop()/array_push() isn't needed? >>>>>>> >>>>>>> Regards, >>>>>>> >>>>>>> -- >>>>>>> Yasuo Ohgaki >>>>>>> yohgaki@ohgaki.net >>>>>>> >>>>>>> -- >>>>>>> PHP Internals - PHP Runtime Development Mailing List >>>>>>> To unsubscribe, visit: http://www.php.net/unsub.php >>>>>>> >>>>>>> >> >> >> -- >> -- >> Tjerk -- Andrew Faulds http://ajf.me/