Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 8th, 2012  |  syntax: PHP  |  size: 0.57 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. class Curry
  4. {
  5.         static public $fn; // fix scope
  6.         static public $arg1; // fix scope
  7.         static public function currify($fn)
  8.         {
  9.                 Curry::$fn = $fn; // fix scope
  10.                 return function($arg1) {
  11.                         Curry::$arg1 = $arg1; // fix scope
  12.                         return function($arg2) {
  13.                                 $fn = Curry::$fn; // fix no soporta Curry::$fn()
  14.                                 return $fn(Curry::$arg1, $arg2);
  15.                         };
  16.                 };
  17.         }
  18.  
  19. }
  20.  
  21. function sum($arg1, $arg2) {
  22.         return $arg1 + $arg2;
  23. }
  24.  
  25. $curry = Curry::currify('sum');
  26. $curry = $curry(3); // fix no soporta fn()()
  27. var_dump(
  28.         array_map(
  29.                 $curry,
  30.                 array(3, 4, 1, 8, 17)
  31.         )
  32. );