Skip to content

Conversation

datibbaw
Copy link
Contributor

@datibbaw datibbaw commented Mar 19, 2020

This has been resurrected from #1385, so some things may have changed; this is partly to see whether the code is still compatible with the engine.

Why

This change allows for a short-circuit predicate to be applied on an array or something that can be traversed, whereby either the predicate has to hold for all elements or at least one element of the array.

For instance, to test whether all elements in an array are of the same type:

array_every($array, function($item) { return $item instanceof FooType; });

Or, at least one element is out of place:

array_some($array, function($item, $index) { return $item != $index; });

Links

Low level changes

The underlying changes revolve around unifying arrays and objects that implement the Traversable interface; this can be compared to similar concepts like Ruby's Enumerable, and allows us to build more flexible function signatures.

It introduces a new zpp type specifier t (for traversable), with an accompanying php_traverse internal function to traverse it.

@iluuu1994
Copy link
Member

@datibbaw Are you planning on pursing this RFC?

@iluuu1994
Copy link
Member

Closing this since there was no response.

@iluuu1994 iluuu1994 closed this Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants