rfc:functional-elements

This is an old revision of the document!


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 examples

UC-1

foreach ($list as $element) {
    $element->method();
}

UC-2

$result = array();
foreach ($list as $element) {
    $result[] = $element->method();
}

UC-3

foreach ($list as $element) {
    if ($element->conditionalMethod()) {
        $element->method();
    }
}

UC-4

$result = array();
foreach ($list as $element) {
    if ($element->conditionalMethod()) {
        $result[] = $element->method();
    }
}
rfc/functional-elements.1204768842.txt.gz · Last modified: 2017/09/22 13:28 (external edit)