emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/dash 4de2189 027/316: [Feature #185] -cut <> in first s


From: ELPA Syncer
Subject: [elpa] externals/dash 4de2189 027/316: [Feature #185] -cut <> in first slot is a function
Date: Mon, 15 Feb 2021 15:57:18 -0500 (EST)

branch: externals/dash
commit 4de21894c0c2fd655fd499ff6643f100383e2844
Author: Matus Goljer <matus.goljer@gmail.com>
Commit: Matus Goljer <matus.goljer@gmail.com>

    [Feature #185] -cut <> in first slot is a function
    
    This follows the Scheme SRFI 26 notation.
---
 README.md          |  2 +-
 dash-functional.el | 31 +++++++++++++++++--------------
 dev/examples.el    |  1 +
 3 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/README.md b/README.md
index 7ae077d..bff1a76 100644
--- a/README.md
+++ b/README.md
@@ -2340,7 +2340,7 @@ See `srfi-26` for detailed description.
 ```el
 (funcall (-cut list 1 <> 3 <> 5) 2 4) ;; => '(1 2 3 4 5)
 (-map (-cut funcall <> 5) '(1+ 1- (lambda (x) (/ 1.0 x)))) ;; => '(6 4 0.2)
-(-filter (-cut < <> 5) '(1 3 5 7 9)) ;; => '(1 3)
+(-map (-cut <> 1 2 3) (list 'list 'vector 'string)) ;; => '((1 2 3) [1 2 3] 
"")
 ```
 
 #### -not `(pred)`
diff --git a/dash-functional.el b/dash-functional.el
index bed5990..4bd2d6d 100644
--- a/dash-functional.el
+++ b/dash-functional.el
@@ -96,7 +96,10 @@ See SRFI-26 for detailed description."
          (args (mapcar (lambda (_) (setq i (1+ i)) (make-symbol (format "D%d" 
i)))
                        (-filter (-partial 'eq '<>) params))))
     `(lambda ,args
-       ,(--map (if (eq it '<>) (pop args) it) params))))
+       ,(let ((body (--map (if (eq it '<>) (pop args) it) params)))
+          (if (eq (car params) '<>)
+              (cons 'funcall body)
+            body)))))
 
 (defun -not (pred)
   "Take a unary predicate PRED and return a unary predicate
@@ -145,11 +148,11 @@ will increment indefinitely.
 
 The closure accepts any number of arguments, which are discarded."
   (let ((inc (or inc 1))
-       (n (or beg 0)))
+    (n (or beg 0)))
     (lambda (&rest _)
       (when (or (not end) (< n end))
-       (prog1 n
-         (setq n (+ n inc)))))))
+    (prog1 n
+      (setq n (+ n inc)))))))
 
 (defvar -fixfn-max-iterations 1000
   "The default maximum number of iterations performed by `-fixfn'
@@ -182,18 +185,18 @@ cdr the final output from HALT-TEST.
 
 In types: (a -> a) -> a -> a."
   (let ((eqfn   (or equal-test 'equal))
-       (haltfn (or halt-test
-                   (-not
-                     (-counter 0 -fixfn-max-iterations)))))
+    (haltfn (or halt-test
+            (-not
+              (-counter 0 -fixfn-max-iterations)))))
     (lambda (x)
       (let ((re (funcall fn x))
-           (halt? (funcall haltfn x)))
-       (while (and (not halt?) (not (funcall eqfn x re)))
-         (setq x     re
-               re    (funcall fn re)
-               halt? (funcall haltfn re)))
-       (if halt? (cons 'halted halt?)
-         re)))))
+        (halt? (funcall haltfn x)))
+    (while (and (not halt?) (not (funcall eqfn x re)))
+      (setq x     re
+        re    (funcall fn re)
+        halt? (funcall haltfn re)))
+    (if halt? (cons 'halted halt?)
+      re)))))
 
 (defun -prodfn (&rest fns)
   "Take a list of n functions and return a function that takes a
diff --git a/dev/examples.el b/dev/examples.el
index ade7eab..c846d08 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -1092,6 +1092,7 @@ new list."
     (defexamples -cut
       (funcall (-cut list 1 <> 3 <> 5) 2 4) => '(1 2 3 4 5)
       (-map (-cut funcall <> 5) '(1+ 1- (lambda (x) (/ 1.0 x)))) => '(6 4 0.2)
+      (-map (-cut <> 1 2 3) (list 'list 'vector 'string)) => '((1 2 3) [1 2 3] 
"")
       (-filter (-cut < <> 5) '(1 3 5 7 9)) => '(1 3))
 
     (defexamples -not



reply via email to

[Prev in Thread] Current Thread [Next in Thread]