3 ms·
fluent expressions (when uses appropriately) can be great for constructing DSLs. Also any time you see boiler plate code take the time to refactor to eliminate
by shaunxcode 18y ago
fluent expressions (when uses appropriately) can be great for constructing DSLs. Also any time you see boiler plate code take the time to refactor to eliminate it - often times figuring out how to do that will make new abstractions apparent. As a matter of practice search for the coolest things you can do in python (list comprehensions etc.), lisp and ruby and figure out how to do things in a similar way (if possible) in php.
Such as:
//python version:
noprimes = [j for i in range(2, 8) for j in range(i*2, 50, i)]
primes = [x for x in range(2, 50) if x not in noprimes]
//phparrayplus version:
$noprimes = xR(2,8)->for_each('xR($x*2,50,$x)->out()')->flatten();
$primes = xR(2,50)->diff($noprimes);
//common lisp:
(loop for x from 0 to 100 if (> (* x x) 3) collect (* 2 x))
//phparrayplus version:
$C = xR(100)->if_only('($x*$x) > 3')->for_each('2*$x');
//factorial in phparrayplus, nothing else to compare this too - just cool:
function fac($n){
return xR(1,$n)->reduce('$x*$y');
}
- apgwoz 18y agoIs "phparrayplus" a library you wrote. If so, where can it be had?
- shaunxcode 18y agoyes, it should be available next week on http://code.google.com/p/phparrayplus http://code.google.com/p/phparrayplus
- jamongkad 18y agoWow that shit is hot! Let us know when you have released the library.