Generic function

Intent
A high-order function/algorithm implementation
Motivation
a generic select->update->eval function with one argument, whose instances/application differ for different (argument, result) types required
Implementation
Simply cache the result into an array or other appropriate type
Examples
class algorithm { var $parameters=array(); function __construct( $select, $update, $eval) { $this->parameters['select'] = $select; $this->parameters['update'] = $update; $this->parameters['eval'] = $eval; } function run($arg) { $selections = $this->parameters['select']($arg); $updates = $this->parameters['update']($selections); return $this->parameters['eval']($updates); } } //or with more syntax, not the parametrisation function algorithm( $select, $update, $eval ) { $args = func_get_args(); $args = array_slice($input, 3); $selections = call_user_func_array( $select, $args); $updates = call_user_func_array( $update, $selections); return call_user_func_array( $eval, $updates); }
Powered by Drupal, an open source content management system