Ejemplo n.º 1
0
function f_reduce($combiner, $in, $identity=null) {
	//adds the first item with the rest, then does the same with the rest.
	if(!empty($in)) {
		return $combiner(
			f_first($in),
			f_reduce(
				$combiner,
				f_rest($in),
				$identity
			)
		);
	} else {
		return $identity;
	}
}
Ejemplo n.º 2
0
function f_flatten($in) {
	return f_reduce(
		function($a, $b) {
			if(is_array($a)) {
				$a = f_flatten($a);
			}
			return array_merge((array)$a, (array)$b);
		},
		$in
	);
}