Func.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Generated by LiveScript 1.4.0
  2. var apply, curry, flip, fix, over, memoize, slice$ = [].slice, toString$ = {}.toString;
  3. apply = curry$(function(f, list){
  4. return f.apply(null, list);
  5. });
  6. curry = function(f){
  7. return curry$(f);
  8. };
  9. flip = curry$(function(f, x, y){
  10. return f(y, x);
  11. });
  12. fix = function(f){
  13. return function(g){
  14. return function(){
  15. return f(g(g)).apply(null, arguments);
  16. };
  17. }(function(g){
  18. return function(){
  19. return f(g(g)).apply(null, arguments);
  20. };
  21. });
  22. };
  23. over = curry$(function(f, g, x, y){
  24. return f(g(x), g(y));
  25. });
  26. memoize = function(f){
  27. var memo;
  28. memo = {};
  29. return function(){
  30. var args, key, arg;
  31. args = slice$.call(arguments);
  32. key = (function(){
  33. var i$, ref$, len$, results$ = [];
  34. for (i$ = 0, len$ = (ref$ = args).length; i$ < len$; ++i$) {
  35. arg = ref$[i$];
  36. results$.push(arg + toString$.call(arg).slice(8, -1));
  37. }
  38. return results$;
  39. }()).join('');
  40. return memo[key] = key in memo
  41. ? memo[key]
  42. : f.apply(null, args);
  43. };
  44. };
  45. module.exports = {
  46. curry: curry,
  47. flip: flip,
  48. fix: fix,
  49. apply: apply,
  50. over: over,
  51. memoize: memoize
  52. };
  53. function curry$(f, bound){
  54. var context,
  55. _curry = function(args) {
  56. return f.length > 1 ? function(){
  57. var params = args ? args.concat() : [];
  58. context = bound ? context || this : this;
  59. return params.push.apply(params, arguments) <
  60. f.length && arguments.length ?
  61. _curry.call(context, params) : f.apply(context, params);
  62. } : f;
  63. };
  64. return _curry();
  65. }