[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash c218e9f 150/426: -split-at/with now makes just one
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash c218e9f 150/426: -split-at/with now makes just one pass over list |
Date: |
Tue, 04 Aug 2015 19:37:20 +0000 |
branch: externals/dash
commit c218e9f1a1c847060aeb37bf8ded93343b703a5e
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
-split-at/with now makes just one pass over list
---
README.md | 6 +++---
dash.el | 31 +++++++++++++++++++++++--------
2 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index 0c392c6..fcedcbc 100644
--- a/README.md
+++ b/README.md
@@ -358,7 +358,7 @@ Returns the tail of `list` starting from the first item for
which (`pred` item)
### -split-at `(n list)`
-Returns a list of ((-take `n` `list`) (-drop `n` `list`))
+Returns a list of ((-take `n` `list`) (-drop `n` `list`)), in no more than one
pass through the list.
```cl
(-split-at 3 '(1 2 3 4 5)) ;; => '((1 2 3) (4 5))
@@ -367,7 +367,7 @@ Returns a list of ((-take `n` `list`) (-drop `n` `list`))
### -split-with `(pred list)`
-Returns a list of ((-take-while `pred` `list`) (-drop-while `pred` `list`))
+Returns a list of ((-take-while `pred` `list`) (-drop-while `pred` `list`)),
in no more than one pass through the list.
```cl
(-split-with 'even? '(1 2 3 4)) ;; => '(nil (1 2 3 4))
@@ -377,7 +377,7 @@ Returns a list of ((-take-while `pred` `list`) (-drop-while
`pred` `list`))
### -separate `(pred list)`
-Returns a list of ((-filter `pred` `list`) (-remove `pred` `list`)).
+Returns a list of ((-filter `pred` `list`) (-remove `pred` `list`)), in one
pass through the list.
```cl
(-separate (lambda (num) (= 0 (% num 2))) '(1 2 3 4 5 6 7)) ;; => '((2 4 6) (1
3 5 7))
diff --git a/dash.el b/dash.el
index 5694e13..6ac7310 100644
--- a/dash.el
+++ b/dash.el
@@ -358,17 +358,32 @@ Returns `nil` both if all items match the predicate, and
if none of the items ma
(--drop-while (funcall pred it) list))
(defun -split-at (n list)
- "Returns a list of ((-take N LIST) (-drop N LIST))"
- (list (-take n list)
- (-drop n list)))
+ "Returns a list of ((-take N LIST) (-drop N LIST)), in no more than one pass
through the list."
+ (let (result)
+ (--dotimes n
+ (when list
+ (!cons (car list) result)
+ (!cdr list)))
+ (list (nreverse result) list)))
-(defmacro --split-with (form list)
+(defmacro --split-with (pred list)
"Anaphoric form of `-split-with'."
- `(list (--take-while ,form ,list)
- (--drop-while ,form ,list)))
+ (let ((l (make-symbol "list"))
+ (r (make-symbol "result"))
+ (c (make-symbol "continue")))
+ `(let ((,l ,list)
+ (,r nil)
+ (,c t))
+ (while (and ,l ,c)
+ (let ((it (car ,l)))
+ (if (not ,pred)
+ (setq ,c nil)
+ (!cons it ,r)
+ (!cdr ,l))))
+ (list (nreverse ,r) ,l))))
(defun -split-with (pred list)
- "Returns a list of ((-take-while PRED LIST) (-drop-while PRED LIST))"
+ "Returns a list of ((-take-while PRED LIST) (-drop-while PRED LIST)), in no
more than one pass through the list."
(--split-with (funcall pred it) list))
(defmacro --separate (form list)
@@ -380,7 +395,7 @@ Returns `nil` both if all items match the predicate, and if
none of the items ma
(list (nreverse ,y) (nreverse ,n)))))
(defun -separate (pred list)
- "Returns a list of ((-filter PRED LIST) (-remove PRED LIST))."
+ "Returns a list of ((-filter PRED LIST) (-remove PRED LIST)), in one pass
through the list."
(--separate (funcall pred it) list))
(defun -partition (n list)
- [elpa] externals/dash 5161361 148/426: Clarify use of anaphoric form of -zip-with, (continued)
- [elpa] externals/dash 5161361 148/426: Clarify use of anaphoric form of -zip-with, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0731333 140/426: Add @vemv to list of contributors, Phillip Lord, 2015/08/04
- [elpa] externals/dash a7ee06e 149/426: Remove extra --separate definition, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3f604cd 151/426: Add -count, Phillip Lord, 2015/08/04
- [elpa] externals/dash fb75a7f 146/426: Add @nicferrier to list of contributors., Phillip Lord, 2015/08/04
- [elpa] externals/dash cc33c2f 153/426: Stop integration tests for Emacs 23, Phillip Lord, 2015/08/04
- [elpa] externals/dash adfafcb 152/426: Add -partition-by-header, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0351ca3 156/426: Add Wilfred Hughes to list of contributors., Phillip Lord, 2015/08/04
- [elpa] externals/dash a4b70f9 154/426: [magnars/dash.el#18] implementing -slice, Phillip Lord, 2015/08/04
- [elpa] externals/dash bd942e1 158/426: inhibit dev from being added to the load-path, Phillip Lord, 2015/08/04
- [elpa] externals/dash c218e9f 150/426: -split-at/with now makes just one pass over list,
Phillip Lord <=
- [elpa] externals/dash d7174ed 160/426: Handle cons-cells properly in -flatten, Phillip Lord, 2015/08/04
- [elpa] externals/dash a559a80 161/426: Added -last, Phillip Lord, 2015/08/04
- [elpa] externals/dash f7a828f 147/426: Add -zip and -zip-with, Phillip Lord, 2015/08/04
- [elpa] externals/dash dac28b0 155/426: Merge pull request #19 from Wilfred/master, Phillip Lord, 2015/08/04
- [elpa] externals/dash a40fc00 162/426: Merge pull request #23 from Fuco1/last, Phillip Lord, 2015/08/04
- [elpa] externals/dash a1b04d8 163/426: Less implementation specific docs for -mapcat, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6ffdc93 157/426: Release 1.1.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash 1396102 165/426: Add -when-let and -if-let macros, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6420bf8 167/426: Add Emanuel Evans to list of contributors, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9371ce4 164/426: Don't use the word collection when meaning list, Phillip Lord, 2015/08/04