On 10/31/16 4:49 PM, Larry Garfield wrote:
> If we're concerned about pw0ning the "first" function name, perhaps it's
> time to start a new prefix:
> 
> iter_first(iterable)
> iter_first_key(iterable)
> array_last(array)
> array_last_key(array)
> 
> Which gives a natural place to start putting iterable-friendly
> alternates of the various array_* functions, for those that make sense. 
> (think iter_fold(), iter_map(), iter_filter(), etc.)
> 
> (Insert debate about parameter order and method-based alternatives here.)

A couple of things before my next idea:

1) I don't know if this has been proposed before
2) I do not understand the internals code well enough
3) This is probably something for PHP 8, but it'd be great for PHP 7.2!
4) ArrayIterator does what I am proposing, but adds overhead for users

What if we made ArrayIterator transparently wrap all array's?

Then we could go with iter_* functions, deprecate array_* functions, and
have syntax that flows like the following?

===
$ary = [1,2,3];

$ary->current(); // returns 1
$ary->reset();   // array is now at index:0
$ary->next();    // array is now at index:1 current => 2
$ary->key();     // 1

// I'll bikeshed the Array type now
$ary->search(2); // 1
$ary->in(2);    // true
$ary->keys();    // [0,1,2]

// threw these in here for good measure, part of \Iterator interface?
$ary->first();   // 1
$ary->last();    // 3
===

Dave
-- 
David Lundgren
dlundg...@syberisle.net
GPG: 0x26F54D7F

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to