[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)))
,n)))
(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)
- [elpa] externals/dash 6931d8a 094/439: Remove Melpa from installation while waiting for it to be included., (continued)
- [elpa] externals/dash 6931d8a 094/439: Remove Melpa from installation while waiting for it to be included., Phillip Lord, 2015/08/04
- [elpa] externals/dash 0c55a4b 090/439: 1.0.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0bd26ac 096/439: Add aliases for -p instead of ?, Phillip Lord, 2015/08/04
- [elpa] externals/dash a2941cd 097/439: Typo, Phillip Lord, 2015/08/04
- [elpa] externals/dash dc6f46c 098/439: Simplify docs-generation using dash., Phillip Lord, 2015/08/04
- [elpa] externals/dash f1c8453 083/439: Rename to dash., Phillip Lord, 2015/08/04
- [elpa] externals/dash eacb6f2 092/439: Docs: Better generation of github urls., Phillip Lord, 2015/08/04
- [elpa] externals/dash 12ed9f6 100/439: Add destructive operations !cons og !cdr, Phillip Lord, 2015/08/04
- [elpa] externals/dash 79b56cc 101/439: Use --each, !cons and !cdr to simplify implementations., Phillip Lord, 2015/08/04
- [elpa] externals/dash 81a3247 104/439: Let -each and -each-while take multiple forms., Phillip Lord, 2015/08/04
- [elpa] externals/dash ba60707 103/439: Use --each-while to simplify implementations.,
Phillip Lord <=
- [elpa] externals/dash eb50d17 106/439: Add Melpa back in., Phillip Lord, 2015/08/04
- [elpa] externals/dash 4fedd2e 099/439: Add -partition and -partition-all, Phillip Lord, 2015/08/04
- [elpa] externals/dash 38eed45 095/439: Add rainbow-dash, Phillip Lord, 2015/08/04
- [elpa] externals/dash 49512b9 107/439: Simplify -take and -drop with --dotimes, Phillip Lord, 2015/08/04
- [elpa] externals/dash ed47814 105/439: Add -dotimes, Phillip Lord, 2015/08/04
- [elpa] externals/dash a08fc14 102/439: Add -each-while, Phillip Lord, 2015/08/04
- [elpa] externals/dash c56925a 111/439: Add font-lock for new functions and the `it` token., Phillip Lord, 2015/08/04
- [elpa] externals/dash a336d78 112/439: Add -only-some?, Phillip Lord, 2015/08/04
- [elpa] externals/dash 03370ea 108/439: Simplify examples-to-docs and examples-to-tests with dash, Phillip Lord, 2015/08/04
- [elpa] externals/dash ba80875 109/439: Nice indentation for --each, --each-while and --dotimes, Phillip Lord, 2015/08/04