rfc:functional-elements

Differences

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

Link to this comparison view

rfc:functional-elements [2008/03/06 02:28]
lstrojny Adding work in progress notice
rfc:functional-elements [2017/09/22 13:28]
Line 1: Line 1:
-This RFC is still work in progress 
----- 
-====== Functional elements for object lists ====== 
-==== 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:​n-relations (e.g. one object, n adapters). This proposal is meant to abstract those iterations in convenient functional constructs. 
  
-==== Current usage patterns ==== 
-=== UC-1 === 
-<code php> 
-foreach ($list as $element) { 
-    $element->​method();​ 
-    array $params = array(), 
-    array $condition_params = array(), 
-    bool $collect = true, 
-    bool $finite = true 
-} 
-</​code>​ 
- 
-=== UC-2 === 
-<code php> 
-$result = array(); 
-foreach ($list as $element) { 
-    $result[] = $element->​method();​ 
-} 
-</​code>​ 
- 
-=== UC-3 === 
-<code php> 
-foreach ($list as $element) { 
-    if ($element->​conditionalMethod()) { 
-        $element->​method();​ 
-    } 
-} 
-</​code>​ 
- 
-=== UC-4 === 
-<code php> 
-$result = array(); 
-foreach ($list as $element) { 
-    if ($element->​conditionalMethod()) { 
-        $result[] = $element->​method();​ 
-    } 
-} 
-</​code>​ 
- 
-==== 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 
-) 
-</​code>​ 
- 
-Iterating over a list of objects, call method "​testMethod"​ and get the list of results: 
-<code php> 
-$result = spl_iterator_element_call($list,​ '​testMethod'​);​ 
-</​code>​ 
- 
-Iterating over a list of objects, call methods "​testMethod"​ (with param "​test"​) and "​otherTestMethod"​ (with param "​other"​) and get the list of results: 
-<code php> 
-$result = spl_iterator_element_call($list,​ array('​testMethod',​ '​otherTestMethod'​),​ array('​test',​ '​other'​));​ 
-</​code>​ 
- 
-Iterating over a list of objects, call method '​testMethod'​ (with param "​test1"​ and "​test2"​) and "​otherTestMethod"​ (with param "​other1"​ and "​other2"​) and get the list of results: 
-<code php> 
-$result = spl_iterator_element_call($list,​ array('​testMethod',​ '​otherTestMethod'​),​ array(array('​test1',​ '​test2'​),​ array('​other1',​ '​other2'​)));​ 
-</​code>​ 
- 
-=== 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 
-) 
-</​code>​ 
rfc/functional-elements.txt · Last modified: 2017/09/22 13:28 (external edit)