eschulte pushed a commit to branch go
in repository elpa.
commit cdaf1a77bc87a10dc12baa795679adc8b4adb6bc
Author: Eric Schulte <[email protected]>
Date: Tue Aug 6 12:13:55 2013 -0600
adding curry, rcurry and compose helpers
---
go-util.el | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/go-util.el b/go-util.el
index 4483369..45b7049 100644
--- a/go-util.el
+++ b/go-util.el
@@ -28,6 +28,24 @@
;;; Code:
(eval-when-compile (require 'cl))
+(defun curry (function &rest arguments)
+ (lexical-let ((function function)
+ (arguments arguments))
+ (lambda (&rest more) (apply function (append arguments more)))))
+
+(defun rcurry (function &rest arguments)
+ (lexical-let ((function function)
+ (arguments arguments))
+ (lambda (&rest more) (apply function (append more arguments)))))
+
+(defun compose (function &rest more-functions)
+ (cl-reduce (lambda (f g)
+ (lexical-let ((f f) (g g))
+ (lambda (&rest arguments)
+ (funcall f (apply g arguments)))))
+ more-functions
+ :initial-value function))
+
(defun rcons (x lst)
(append lst (list x)))