rfc:cachediterable

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:cachediterable [2021/06/15 13:32] tandrerfc:cachediterable [2021/06/29 14:24] (current) tandre
Line 3: Line 3:
   * Date: 2021-02-06   * Date: 2021-02-06
   * Author: Tyson Andre, tandre@php.net   * Author: Tyson Andre, tandre@php.net
-  * Status: Under Discussion+  * Status: Declined
   * Implementation: https://github.com/php/php-src/pull/6655   * Implementation: https://github.com/php/php-src/pull/6655
   * First Published at: https://wiki.php.net/rfc/cachediterable   * First Published at: https://wiki.php.net/rfc/cachediterable
Line 11: Line 11:
 Currently, PHP does not provide a built-in way to store the state of an arbitrary iterable for reuse later (when the iterable has arbitrary keys, or when keys might be repeated). It would be useful to do so for many use cases, such as: Currently, PHP does not provide a built-in way to store the state of an arbitrary iterable for reuse later (when the iterable has arbitrary keys, or when keys might be repeated). It would be useful to do so for many use cases, such as:
  
-  - Creating a rewindable copy of a non-rewindable Traversable (e.g. a ''Generator'') before passing that copy to a function that consumes an iterable/Traversable. (''new CachedIterator(my_generator())'')+  - Creating a rewindable copy of a non-rewindable Traversable (e.g. a ''Generator'') before passing that copy to a function that consumes an iterable/Traversable. (''new ImmutableIterable(my_generator())'')
   - Generating an ''IteratorAggregate'' from a class still implementing ''Iterator'' (e.g. ''SplObjectStorage'') so that code can independently iterate over the key-value sequences. \\ (e.g. ''foreach ($immutableKeyValueSequence as $k1 => $v1) { foreach ($immutableKeyValueSequence as $k2 => $v2) { /* process pairs */ } }'')   - Generating an ''IteratorAggregate'' from a class still implementing ''Iterator'' (e.g. ''SplObjectStorage'') so that code can independently iterate over the key-value sequences. \\ (e.g. ''foreach ($immutableKeyValueSequence as $k1 => $v1) { foreach ($immutableKeyValueSequence as $k2 => $v2) { /* process pairs */ } }'')
   - Providing internal or userland helpers such as ''iterable_flip(iterable $input)'', ''iterable_take(iterable $input, int $limit)'', ''iterable_chunk(iterable $input, int $chunk_size)'' that act on iterables with arbitrary key/value sequences and have return values including iterables with arbitrary key/value sequences   - Providing internal or userland helpers such as ''iterable_flip(iterable $input)'', ''iterable_take(iterable $input, int $limit)'', ''iterable_chunk(iterable $input, int $chunk_size)'' that act on iterables with arbitrary key/value sequences and have return values including iterables with arbitrary key/value sequences
Line 344: Line 344:
   * More methods may be useful to add to ''ImmutableIterable'', e.g. for returning a sorted copy, returning a slice(range of entries), returning a copy sorted by keys/values, quickly returning the index/corresponding value of the first occurrence of ''mixed $key'' etc.   * More methods may be useful to add to ''ImmutableIterable'', e.g. for returning a sorted copy, returning a slice(range of entries), returning a copy sorted by keys/values, quickly returning the index/corresponding value of the first occurrence of ''mixed $key'' etc.
   * This may or may not be useful for future data types, e.g. a ''MapObject'' (hash map on any key type) type and may potentially be useful for converting some existing internal/user-defined ''Iterable'' types to ''IteratorAggregate'' types.   * This may or may not be useful for future data types, e.g. a ''MapObject'' (hash map on any key type) type and may potentially be useful for converting some existing internal/user-defined ''Iterable'' types to ''IteratorAggregate'' types.
-    * A new ''IterableAggregate'' subclass such as ''CachedIterator'' could be added to compute values [[https://en.wikipedia.org/wiki/Lazy_evaluation|lazily(on-demand)]] in contrast to ''ImmutableIterable'', which [[https://en.wikipedia.org/wiki/Eager_evaluation|evaluates the entire iterable in the constructor]].+    * A new ''IterableAggregate'' subclass such as ''CachedIterator''/''CachedIterable'' could be added to compute values [[https://en.wikipedia.org/wiki/Lazy_evaluation|lazily(on-demand)]] in contrast to ''ImmutableIterable'', which [[https://en.wikipedia.org/wiki/Eager_evaluation|evaluates the entire iterable in the constructor]].
  
-===== Proposed Voting Choices ===== +===== Vote ===== 
-Yes/No, requiring a 2/3 majority.+This is a Yes/No vote, requiring a 2/3 majority. Voting started on June 15, 2021 and ends on June 29, 2021. 
 + 
 +<doodle title="Add ImmutableIterable to core" auth="tandre" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle> 
 + 
 +==== Poll: Reason for voting against this RFC ==== 
 + 
 +<doodle title="Reasons for voting against the ImmutableIterable RFC" auth="tandre" voteType="multi" closed="true"> 
 +   * Object to the namespace choice 
 +   * Object to the name 
 +   * Object to the implementation 
 +   * Don't see a use case 
 +   * Other 
 +</doodle>
  
 ===== References ===== ===== References =====
  
   * [[https://externals.io/message/113061#113066|Proposal: Add ReverseArrayIterator and ForwardArrayIterator to SPL]]   * [[https://externals.io/message/113061#113066|Proposal: Add ReverseArrayIterator and ForwardArrayIterator to SPL]]
-  * [[rfc:cachediterable_straw_poll|Straw poll: Namespace to use for ImmutableIterable and iterable functionality]]+  * [[rfc:cachediterable_straw_poll|Straw poll: Namespace to use for CachedIterable and iterable functionality]] 
 +  * https://externals.io/message/114834  RFC: CachedIterable (rewindable, allows any key&repeating keys) 
 +  * [[https://externals.io/message/114887|[VOTE] ImmutableIterable (immutable, rewindable, allows any key&repeating keys)]]
  
 ===== Rejected Features ===== ===== Rejected Features =====
 +
 +==== Rejected: Alternative namespaces ====
 +
 +[[rfc:cachediterable_straw_poll|Straw poll: Namespace to use for CachedIterable and iterable functionality]] did not indicate a majority of voters preferred alternative namespace choices for a namespace over not using a namespace for newly added caches. This chooses the global namespace to maintain consistency with existing spl classes and interfaces.
 +
  
 ==== Rejected: ArrayAccess ==== ==== Rejected: ArrayAccess ====
Line 367: Line 389:
 ''ImmutableIterable'' evaluates the entire iterable in its constructor ([[https://en.wikipedia.org/wiki/Eager_evaluation|eagerly]] instead of [[https://en.wikipedia.org/wiki/Lazy_evaluation|lazily]]) for the following reasons: ''ImmutableIterable'' evaluates the entire iterable in its constructor ([[https://en.wikipedia.org/wiki/Eager_evaluation|eagerly]] instead of [[https://en.wikipedia.org/wiki/Lazy_evaluation|lazily]]) for the following reasons:
  
-  * Exceptions will be thrown during construction instead of during iteration or call to count()/keyAt()/valueAt() - it would be unintuitive for those to throw ''SomeUserlandFrameworkException''+  * If this is generated from a data structure, the behavior may be unintuitive if the underlying data is modified while iterating over the sequence of keys and values if this were to be evaluated lazily instead of eagerly. 
 +  * Evaluating the entire iterable in the constructor ensures that exceptions will be thrown during construction instead of during iteration or call to count()/keyAt()/valueAt() - it would be unintuitive for those iteration methods to throw ''SomeUserlandFrameworkException''
   * This is easier to understand, debug, serialize, and represent   * This is easier to understand, debug, serialize, and represent
   * If the underlying iterable (e.g. a Generator) has side effects, having those side effects take place immediately instead of being interleaved with other parts of the program may be easier to reason about.   * If the underlying iterable (e.g. a Generator) has side effects, having those side effects take place immediately instead of being interleaved with other parts of the program may be easier to reason about.
   * The majority of use cases of ''Traversable''s would iterate over the entire Traversable at some point.   * The majority of use cases of ''Traversable''s would iterate over the entire Traversable at some point.
   * Eagerly evaluating iterables reduces the memory needed by the implementation. The amount of memory needed to represent this is much lower (without the need to store the underlying iterable, potentially the most recent exception(s) thrown by the undlying iterable, etc).   * Eagerly evaluating iterables reduces the memory needed by the implementation. The amount of memory needed to represent this is much lower (without the need to store the underlying iterable, potentially the most recent exception(s) thrown by the undlying iterable, etc).
 +
  
 The addition of an iterable library class that evaluates arguments on-demand is mentioned in the "future scope" section. The addition of an iterable library class that evaluates arguments on-demand is mentioned in the "future scope" section.
Line 439: Line 463:
  
   * 0.2: Use optimized build with opcache enabled for benchmark timings   * 0.2: Use optimized build with opcache enabled for benchmark timings
-  * 0.3: Rename from ''CachedIterable'' to ''ImmutableKeyValueSequence'' (the lack of clarity about the functionality associated with the name ''CachedIterable'' being eagerly evalulated was mentioned *after* most of the responses to the straw poll were already submitted)+  * 0.3: Rename from ''CachedIterable'' to ''ImmutableKeyValueSequence'' (the lack of clarity about the functionality associated with the name ''CachedIterable'' being eagerly evalulated was mentioned *after* most of the responses to the straw poll were already submitted). \\ Other names starting with ''Cached*'' were rejected for the same reason.
   * 0.3.1: Add ''__set_state''   * 0.3.1: Add ''__set_state''
   * 0.4.0: Rename from ''ImmutableKeyValueSequence'' to ''ImmutableIterable''   * 0.4.0: Rename from ''ImmutableKeyValueSequence'' to ''ImmutableIterable''
  
rfc/cachediterable.txt · Last modified: 2021/06/29 14:24 by tandre