Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. <?php
  2.  
  3. function tail($fn)
  4. {
  5. $underCall = false;
  6. $pool = [];
  7.  
  8. return function (...$args) use (&$fn, &$underCall, &$pool) {
  9. $result = null;
  10. $pool[] = $args;
  11.  
  12. if (!$underCall) {
  13. $underCall = true;
  14. while ($pool) {
  15. $head = array_shift($pool);
  16. $result = $fn(...$head);
  17. }
  18. $underCall = false;
  19. }
  20.  
  21. return $result;
  22. };
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement