2011年9月13日星期二

Sameer Borate's Blog: Functional programming with Underscore.php


In a new post to his blog Sameer Borate looks at using the Underscore.php library to do a little functional programming in PHP. Underscrore.phpis a PHP port of Underscrore.js.



Underscore.php provides a utility library for PHP that provides a lot of the functional programming support that a programmer would expect in Ruby, but without adding much overhead during execution. The only caveat is that underscore.php requires PHP 5.3 or greater. Although you could accomplish some of the things using PHP's built in functions, the functional approach looks intuitive and easy to work with.


He gives a few simple code examples - one using the "pluck" method to pull certain values out of an array, the "map" method to apply a transformation to each item in an array and some OOP examples showing the use of the "max" and "template" methods.

没有评论:

发表评论