[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 66ffaa6 072/426: Add !interpose
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 66ffaa6 072/426: Add !interpose |
Date: |
Tue, 04 Aug 2015 19:36:47 +0000 |
branch: externals/dash
commit 66ffaa668dcd07ef1752001502e3a100c2cbca0c
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Add !interpose
---
README.md | 11 +++++++++++
bang.el | 11 +++++++++++
examples.el | 5 +++++
3 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index d8081dc..f488889 100644
--- a/README.md
+++ b/README.md
@@ -20,6 +20,7 @@ Or you can just dump `bang.el` in your load path somewhere.
* [!keep](#keep-fn-list) `(fn list)`
* [!concat](#concat-rest-lists) `(&rest lists)`
* [!mapcat](#mapcat-fn-list) `(fn list)`
+* [!interpose](#interpose-sep-list) `(sep list)`
* [!first](#first-fn-list) `(fn list)`
* [!partial](#partial-fn-rest-args) `(fn &rest args)`
* [!rpartial](#rpartial-fn-rest-args) `(fn &rest args)`
@@ -159,6 +160,16 @@ Thus function `fn` should return a collection.
(!!mapcat (list 0 it) '(1 2 3)) ;; => '(0 1 0 2 0 3)
```
+### !interpose `(sep list)`
+
+Returns a new list of all elements in `list` separated by `sep`.
+
+```cl
+(!interpose "-" '()) ;; => '()
+(!interpose "-" '("a")) ;; => '("a")
+(!interpose "-" '("a" "b" "c")) ;; => '("a" "-" "b" "-" "c")
+```
+
### !first `(fn list)`
Returns the first x in `list` where (`fn` x) is non-nil, else nil.
diff --git a/bang.el b/bang.el
index 128aae5..78c21a5 100644
--- a/bang.el
+++ b/bang.el
@@ -144,6 +144,17 @@ the supplied LISTS."
Thus function FN should return a collection."
(!!mapcat (funcall fn it) list))
+(defun !interpose (sep list)
+ "Returns a new list of all elements in LIST separated by SEP."
+ (let (result)
+ (when list
+ (setq result (cons (car list) result))
+ (setq list (cdr list)))
+ (while list
+ (setq result (cons (car list) (cons sep result)))
+ (setq list (cdr list)))
+ (nreverse result)))
+
(defun !partial (fn &rest args)
"Takes a function FN and fewer than the normal arguments to FN,
and returns a fn that takes a variable number of additional ARGS.
diff --git a/examples.el b/examples.el
index 524fe67..970953d 100644
--- a/examples.el
+++ b/examples.el
@@ -58,6 +58,11 @@
(!mapcat (lambda (item) (list 0 item)) '(1 2 3)) => '(0 1 0 2 0 3)
(!!mapcat (list 0 it) '(1 2 3)) => '(0 1 0 2 0 3))
+(defexamples !interpose
+ (!interpose "-" '()) => '()
+ (!interpose "-" '("a")) => '("a")
+ (!interpose "-" '("a" "b" "c")) => '("a" "-" "b" "-" "c"))
+
(defexamples !first
(!first 'even? '(1 2 3)) => 2
(!first 'even? '(1 3 5)) => nil
- [elpa] externals/dash 4205e58 064/426: Add clojure threading macros, !-> and !->>, (continued)
- [elpa] externals/dash 4205e58 064/426: Add clojure threading macros, !-> and !->>, Phillip Lord, 2015/08/04
- [elpa] externals/dash cd2a793 069/426: Run travis-ci on both E23 and E24, Phillip Lord, 2015/08/04
- [elpa] externals/dash 1a7ad85 065/426: Mention Melpa in README, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6be4c03 058/426: !first, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0991c29 057/426: Added some common aliases, Phillip Lord, 2015/08/04
- [elpa] externals/dash ca3eea7 070/426: Fix examples-to-docs to support documenting macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash a6323eb 059/426: Add some tests that verify that the lists are evaled by the anaphoric macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash b29a5bb 071/426: Use make-symbol in macros to avoid names clashing., Phillip Lord, 2015/08/04
- [elpa] externals/dash 6520496 060/426: First release, remove warning., Phillip Lord, 2015/08/04
- [elpa] externals/dash 8bd82c7 051/426: Show empty lists as '() instead of nil in docs., Phillip Lord, 2015/08/04
- [elpa] externals/dash 66ffaa6 072/426: Add !interpose,
Phillip Lord <=
- [elpa] externals/dash ec6a85f 074/426: Add threading macro !!-> with `it` as placeholder., Phillip Lord, 2015/08/04
- [elpa] externals/dash 6238f8f 077/426: Add !split-with, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4e76865 075/426: Add !take-while, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3802890 082/426: Simplify !concat, Phillip Lord, 2015/08/04
- [elpa] externals/dash ec835e4 081/426: Add !split-at, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0dab44c 084/426: Add -flatten, Phillip Lord, 2015/08/04
- [elpa] externals/dash 047eeea 066/426: Run tests on Emacs 24., Phillip Lord, 2015/08/04
- [elpa] externals/dash 9410f7e 073/426: Add !replace-where, Phillip Lord, 2015/08/04
- [elpa] externals/dash 123eaaa 078/426: Docs: Refer to !replace-where from !!replace-where., Phillip Lord, 2015/08/04
- [elpa] externals/dash 70488c2 063/426: Add !rpartial, Phillip Lord, 2015/08/04