rfc:functional-elements
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:functional-elements [2008/03/06 02:12] – Adding usage examples lstrojny | rfc:functional-elements [2008/03/17 09:40] – lstrojny | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Functional elements | + | This RFC is still in progress |
+ | ====== Functional elements | ||
==== Abstract ==== | ==== Abstract ==== | ||
- | A common pattern in PHP is iterating through a list of objects and executing certain methods of the function. This is especially common when it comes to 1: | + | A common pattern in PHP is iterating through a list of objects and executing certain methods of the objects. This is especially common when it comes to 1: |
==== Current usage patterns ==== | ==== Current usage patterns ==== | ||
- | === UC-1 === | + | === UC-1: Iterating over an aggregation of objects |
<code php> | <code php> | ||
foreach ($list as $element) { | foreach ($list as $element) { | ||
- | $element-> | + | $element-> |
- | array $condition_params = array(), | + | |
- | bool $collect = true, | + | |
- | bool $finite = true | + | |
} | } | ||
</ | </ | ||
- | === UC-2 === | + | === UC-2: Iterating over an aggregation of objects and keeping the results |
<code php> | <code php> | ||
$result = array(); | $result = array(); | ||
Line 22: | Line 20: | ||
</ | </ | ||
- | === UC-3 === | + | === UC-3: Iterating over an aggregation of objects and conditionally executing a method |
<code php> | <code php> | ||
foreach ($list as $element) { | foreach ($list as $element) { | ||
Line 31: | Line 29: | ||
</ | </ | ||
- | === UC-4 === | + | === UC-4: Iterating over an aggregation of objects and conditionally executing a method while keeping the results |
<code php> | <code php> | ||
$result = array(); | $result = array(); | ||
Line 41: | Line 39: | ||
</ | </ | ||
- | ==== Extracted functions ==== | ||
- | === spl_iterator_element_call() === | ||
- | <code php> | ||
- | array|bool spl_iterator_element_call( | ||
- | array|Iterator $iterator, | ||
- | string|array $methods, | ||
- | array $params = array(), | ||
- | bool $collect = true | ||
- | ) | ||
- | </ | ||
- | Iterating | + | |
+ | ==== Required functionality ==== | ||
+ | Extracting the required functionality to leads to the following required additions: | ||
+ | * [[rfc: | ||
+ | * [[rfc:: | ||
+ | * [[rfc: | ||
+ | * function iterator_true(): | ||
+ | * function iterator_false(): | ||
+ | |||
+ | ==== Modified use cases ==== | ||
+ | === UC-1: Iterating over an aggregation of objects === | ||
<code php> | <code php> | ||
- | $result = spl_iterator_element_call($list, 'testMethod'); | + | iterate(new CallIterator($list, 'method')); |
</ | </ | ||
- | Iteratoring | + | === UC-2: Iterating |
<code php> | <code php> | ||
- | $result = spl_iterator_element_call($list, | + | $result = iterate(new CallIterator($list, 'method' |
</ | </ | ||
- | === spl_iterator_element_call_conditional() === | ||
- | <code php> | ||
- | array|mixed spl_iterator_element_call_conditional( | ||
- | array|Iterator $iterator, | ||
- | string|array $methods, | ||
- | string|array $conditions, | ||
- | array $params = array(), | ||
- | array $condition_params = array(), | ||
- | bool $collect = true, | ||
- | bool $finite = true | ||
- | ) | ||
- | </ |
rfc/functional-elements.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1