rfc:comprehensions

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
rfc:comprehensions [2019/03/11 11:53]
nikic fix typos in code
rfc:comprehensions [2019/04/05 01:10] (current)
crell Revise explanation of generator choice.
Line 171: Line 171:
   - In most cases it doesn'​t matter either way. The result will be put into a foreach() loop and that will be the end of it.   - In most cases it doesn'​t matter either way. The result will be put into a foreach() loop and that will be the end of it.
   - Cases where it does matter are where the list is especially large, or especially expensive to generate and only selected values will be used.  In those cases a generator is superior as it minimizes the memory and CPU usage (respectively) needed to represent values.   - Cases where it does matter are where the list is especially large, or especially expensive to generate and only selected values will be used.  In those cases a generator is superior as it minimizes the memory and CPU usage (respectively) needed to represent values.
-  - If an actual array is desired, converting a generator to an array is a trivial call to ''​%%iterator_to_array()%%''​. ​ Converting an array to an iterator, while technically easy, has no benefit aside from compatibility with other iterators.  ​Returning ​generatorthereforeoffers ​the most benefit with the fewest limitations.+  - If an actual array is desired, converting a generator to an array is a trivial call to ''​%%iterator_to_array()%%''​. ​ Converting an array to an iterator, while technically easy, has no benefit aside from compatibility with other iterators. 
 +  - That is, greedy-list value can be composed out of a lazy-list value and a expansion operation. ​ Howevera lazy-list value cannot be composed from a greedy-list. ​ That means since both are valuable, the one that provides both via syntactic composition is the superior approach.
   - A compact syntax to produce a generator allows for some nifty functional programming techniques that until now have been verbose to implement for non-array iterators.   - A compact syntax to produce a generator allows for some nifty functional programming techniques that until now have been verbose to implement for non-array iterators.
  
rfc/comprehensions.txt · Last modified: 2019/04/05 01:10 by crell