[Top][All Lists]

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

[elpa] externals/dash ba60707 103/439: Use --each-while to simplify impl

From: Phillip Lord
Subject: [elpa] externals/dash ba60707 103/439: Use --each-while to simplify implementations.
Date: Tue, 04 Aug 2015 20:26:54 +0000

branch: externals/dash
commit ba607079bd81719ab7b08e21b0ac34127e4b1d85
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>

    Use --each-while to simplify implementations.
 dash.el |   34 ++++++++++------------------------
 1 files changed, 10 insertions(+), 24 deletions(-)

diff --git a/dash.el b/dash.el
index 3c38370..0a167ce 100644
--- a/dash.el
+++ b/dash.el
@@ -167,17 +167,11 @@ Alias: `-reject'"
 Thus function FN should return a collection."
   (--mapcat (funcall fn it) list))
-;; can be simplified with an --each that stops at a predicate, --each-while?
 (defmacro --first (form list)
   "Anaphoric form of `-first'."
-  (let ((l (make-symbol "list"))
-        (n (make-symbol "needle")))
-    `(let ((,l ,list)
-           (,n nil))
-       (while (and ,l (not ,n))
-         (let ((it (car ,l)))
-           (when ,form (setq ,n it)))
-         (!cdr ,l))
+  (let ((n (make-symbol "needle")))
+    `(let (,n)
+       (--each-while ,list (not ,n) (when ,form (setq ,n it)))
 (defun -first (fn list)
@@ -209,14 +203,9 @@ Alias: `-some?'"
 (defmacro --all? (form list)
   "Anaphoric form of `-all?'."
-  (let ((l (make-symbol "list"))
-        (a (make-symbol "all")))
-    `(let ((,l ,list)
-           (,a t))
-       (while (and ,a ,l)
-         (let ((it (car ,l)))
-           (setq ,a ,form))
-         (!cdr ,l))
+  (let ((a (make-symbol "all")))
+    `(let ((,a t))
+       (--each-while ,list ,a (setq ,a ,form))
        (---truthy? ,a))))
 (defun -all? (fn list)
@@ -244,6 +233,7 @@ Alias: `-every?'"
 (defalias '-none-p '-none?)
 (defalias '--none-p '--none?)
+;; simplify with a --dotimes
 (defun -take (n list)
   "Returns a new list of the first N items in LIST, or all items if there are 
fewer than N."
   (let (result)
@@ -262,13 +252,9 @@ Alias: `-every?'"
 (defmacro --take-while (form list)
   "Anaphoric form of `-take-while'."
-  (let ((l (make-symbol "list"))
-        (r (make-symbol "result")))
-    `(let ((,l ,list)
-           (,r '()))
-       (while (and ,l (let ((it (car ,l))) ,form))
-         (!cons (car ,l) ,r)
-         (!cdr ,l))
+  (let ((r (make-symbol "result")))
+    `(let (,r)
+       (--each-while ,list ,form (!cons it ,r))
        (nreverse ,r))))
 (defun -take-while (fn list)

reply via email to

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