[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 5232399 238/439: Merge pull request #50 from kuris
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 5232399 238/439: Merge pull request #50 from kurisuwhyte/master |
Date: |
Tue, 04 Aug 2015 20:28:25 +0000 |
branch: externals/dash
commit 52323996bf99de25d04e59b66aa130a04605878f
Merge: 6d43c4f 20eb331
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Merge pull request #50 from kurisuwhyte/master
Provides `-compose` for function composition
---
README.md | 15 +++++++++++++++
dash-functional.el | 10 ++++++++++
dev/examples.el | 8 +++++++-
3 files changed, 32 insertions(+), 1 deletions(-)
diff --git a/README.md b/README.md
index d4431e4..3611b7b 100644
--- a/README.md
+++ b/README.md
@@ -164,6 +164,7 @@ These combinators require Emacs 24 for its lexical scope.
So they are offered in
* [-partial](#-partial-fn-rest-args) `(fn &rest args)`
* [-rpartial](#-rpartial-fn-rest-args) `(fn &rest args)`
* [-juxt](#-juxt-rest-fns) `(&rest fns)`
+* [-compose](#-compose-rest-fns) `(&rest fns)`
* [-applify](#-applify-fn) `(fn)`
* [-on](#-on-operator-transformer) `(operator transformer)`
* [-flip](#-flip-func) `(func)`
@@ -1134,6 +1135,20 @@ applying each fn to the args (left-to-right).
(-map (-juxt 'identity 'square) '(1 2 3)) ;; => '((1 1) (2 4) (3 9))
```
+#### -compose `(&rest fns)`
+
+Takes a list of functions and returns a fn that is the
+composition of those fns. The returned fn takes a variable
+number of arguments, and returns the result of applying
+each fn to the result of applying the previous fn to
+the arguments (right-to-left).
+
+```cl
+(funcall (-compose 'square '+) 2 3) ;; => (square (+ 2 3))
+(funcall (-compose 'identity 'square) 3) ;; => (square 3)
+(funcall (-compose 'square 'identity) 3) ;; => (square 3)
+```
+
#### -applify `(fn)`
Changes an n-arity function `fn` to a 1-arity function that
diff --git a/dash-functional.el b/dash-functional.el
index e7f5b20..4a00720 100644
--- a/dash-functional.el
+++ b/dash-functional.el
@@ -52,6 +52,16 @@ number of args, and returns a list containing the result of
applying each fn to the args (left-to-right)."
(lambda (&rest args) (mapcar (lambda (x) (apply x args)) fns)))
+(defun -compose (&rest fns)
+ "Takes a list of functions and returns a fn that is the
+composition of those fns. The returned fn takes a variable
+number of arguments, and returns the result of applying
+each fn to the result of applying the previous fn to
+the arguments (right-to-left)."
+ (lambda (&rest args)
+ (car (-reduce-r-from (lambda (fn xs) (list (apply fn xs)))
+ args fns))))
+
(defun -applify (fn)
"Changes an n-arity function FN to a 1-arity function that
expects a list with n items as arguments"
diff --git a/dev/examples.el b/dev/examples.el
index 6c3868e..b0756dc 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -422,7 +422,13 @@
(defexamples -juxt
(funcall (-juxt '+ '-) 3 5) => '(8 -2)
- (-map (-juxt 'identity 'square) '(1 2 3)) => '((1 1) (2 4) (3 9))))
+ (-map (-juxt 'identity 'square) '(1 2 3)) => '((1 1) (2 4) (3 9)))
+
+ (defexamples -compose
+ (funcall (-compose 'square '+) 2 3) => (square (+ 2 3))
+ (funcall (-compose 'identity 'square) 3) => (square 3)
+ (funcall (-compose 'square 'identity) 3) => (square 3)
+ (funcall (-compose (-compose 'not 'even?) 'square) 3) => (funcall
(-compose 'not (-compose 'even? 'square)) 3)))
(defexamples -applify
(-map (-applify '+) '((1 1 1) (1 2 3) (5 5 5))) => '(3 6 15)
- [elpa] externals/dash 1812a17 226/439: Complete dash and dash-functional split, (continued)
- [elpa] externals/dash 1812a17 226/439: Complete dash and dash-functional split, Phillip Lord, 2015/08/04
- [elpa] externals/dash f1049f1 216/439: Add dash-functional back, now dependent on dash.el, Phillip Lord, 2015/08/04
- [elpa] externals/dash 39d20f2 228/439: Release 2.0.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash 81e43ad 229/439: Add -union to list of highlighted symbols., Phillip Lord, 2015/08/04
- [elpa] externals/dash 515e2d3 230/439: Use `comparator` instead of `predicate` for sort., Phillip Lord, 2015/08/04
- [elpa] externals/dash 6cc7727 234/439: Release 2.1.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6eeb692 236/439: Provide an implementation of function composition., Phillip Lord, 2015/08/04
- [elpa] externals/dash 23ab726 227/439: Improve formatting of docs, Phillip Lord, 2015/08/04
- [elpa] externals/dash 87c8b91 232/439: Add indexing operations, Phillip Lord, 2015/08/04
- [elpa] externals/dash 1e2bd96 233/439: Merge pull request #48 from Fuco1/index-operations, Phillip Lord, 2015/08/04
- [elpa] externals/dash 5232399 238/439: Merge pull request #50 from kurisuwhyte/master,
Phillip Lord <=
- [elpa] externals/dash 20eb331 237/439: Updates the documentation., Phillip Lord, 2015/08/04
- [elpa] externals/dash 6d43c4f 235/439: Fix switched around doc strings for -find-index/indices, Phillip Lord, 2015/08/04
- [elpa] externals/dash 13e0a35 240/439: Release 2.2.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash dbcb3ef 231/439: Update README, Phillip Lord, 2015/08/04
- [elpa] externals/dash bf85b21 242/439: Change &optional branches to &rest branches in `-if-let`s, Phillip Lord, 2015/08/04
- [elpa] externals/dash 8e2422a 239/439: Add Christina Whyte (@kurisuwhyte) to list of contributors, Phillip Lord, 2015/08/04
- [elpa] externals/dash b4d84de 243/439: Add debug declarations for `-when-let`s and `-if-let`s, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6d20aa0 241/439: If has an indent function 2, not 1, Phillip Lord, 2015/08/04
- [elpa] externals/dash 459322d 244/439: Update docs, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9936885 245/439: Merge pull request #51 from Fuco1/debug-decl, Phillip Lord, 2015/08/04