note 43822 modified in function.array-filter by vrana

From: Date: Tue, 17 Aug 2004 13:57:53 +0000
Subject: note 43822 modified in function.array-filter by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-80002@lists.php.net to get a copy of this message
Some of PHP's array functions play a prominent role in so called functional programming languages, where they show up under a slightly different name: <?php array_filter() -> filter(), array_map() -> map(), array_reduce() -> foldl() ("fold left") ?> Functional programming is a paradigm which centers around the side-effect free evaluation of functions. A program execution is a call of a function, which in turn might be defined by many other functions. One idea is to use functions to create special purpose functions from other functions. The array functions mentioned above allow you compose new functions on arrays. E.g. array_sum = array_map("sum", $arr). This leads to a style of programming that looks much like algebra, e.g. the Bird/Meertens formalism. E.g. a mathematician might state map(f o g) = map(f) o map(g) the so called "loop fusion" law. Many functions on arrays can be created by the use of the foldr() function (which works like foldl, but eating up array elements from the right). I can't get into detail here, I just wanted to provide a hint about where this stuff also shows up and the theory behind it. --was-- Some of PHP's array functions play a prominent role in so called functional programming languages, where they show up under a slightly different name: array_filter() -> filter(), array_map() -> map(), array_reduce() -> foldl() ("fold left") Functional programming is a paradigm which centers around the side-effect free evaluation of functions. A program execution is a call of a function, which in turn might be defined by many other functions. One idea is to use functions to create special purpose functions from other functions. The array functions mentioned above allow you compose new functions on arrays. E.g. array_sum = array_map("sum", $arr). This leads to a style of programming that looks much like algebra, e.g. the Bird/Meertens formalism. E.g. a mathematician might state map(f o g) = map(f) o map(g) the so called "loop fusion" law. Many functions on arrays can be created by the use of the foldr() function (which works like foldl, but eating up array elements from the right). I can't get into detail here, I just wanted to provide a hint about where this stuff also shows up and the theory behind it. http://php.net/manual/en/function.array-filter.php

« previous php.notes (#80002) next »