[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash f0dd4cc 301/439: Add -annotate
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash f0dd4cc 301/439: Add -annotate |
Date: |
Tue, 04 Aug 2015 20:29:26 +0000 |
branch: externals/dash
commit f0dd4cc4fc4c638e6decf5472cf6f109c40ef449
Author: Steve Lamb <address@hidden>
Commit: Steve Lamb <address@hidden>
Add -annotate
---
README.md | 14 +++++++++++++-
dash.el | 10 ++++++++++
dev/examples.el | 5 +++++
readme-template.md | 2 +-
4 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 7e55dde..155284f 100644
--- a/README.md
+++ b/README.md
@@ -134,6 +134,7 @@ Operations dual to reductions, building lists from seed
value rather than consum
* [-interleave](#-interleave-rest-lists) `(&rest lists)`
* [-zip-with](#-zip-with-fn-list1-list2) `(fn list1 list2)`
* [-zip](#-zip-rest-lists) `(&rest lists)`
+* [-annotate](#-annotate-fn-list) `(fn list)`
* [-first](#-first-pred-list) `(pred list)`
* [-last](#-last-pred-list) `(pred list)`
* [-first-item](#-first-item-list) `(list)`
@@ -1103,6 +1104,17 @@ of cons cells. Otherwise, return the groupings as a list
of lists.
(-zip '(1 2 3 4) '(4 5 6)) ;; => '((1 . 4) (2 . 5) (3 . 6))
```
+#### -annotate `(fn list)`
+
+Returns a list of cons cells where each cell is `fn` applied to each
+element of `list` paired with the unmodified element of `list`.
+
+```cl
+(-annotate '1+ '(1 2 3)) ;; => '((2 . 1) (3 . 2) (4 . 3))
+(-annotate 'length '(("h" "e" "l" "l" "o") ("hello" "world"))) ;; => '((5 "h"
"e" "l" "l" "o") (2 "hello" "world"))
+(--annotate (< 1 it) '(0 1 2 3)) ;; => '((nil . 0) (nil . 1) (t . 2) (t . 3))
+```
+
#### -first `(pred list)`
Returns the first x in `list` where (`pred` x) is non-nil, else nil.
@@ -1669,7 +1681,7 @@ Change `readme-template.md` or `examples-to-docs.el`
instead.
- [Emanuel Evans](https://github.com/shosti) contributed `-if-let`,
`-when-let` and `-insert-at`.
- [Johan Andersson](https://github.com/rejeep) contributed `-sum`, `-product`
and `-same-items?`
- [Christina Whyte](https://github.com/kurisuwhyte) contributed `-compose`
- - [Steve Lamb](https://github.com/steventlamb) contributed an n-ary version
of `-zip`
+ - [Steve Lamb](https://github.com/steventlamb) contributed `-annotate` and an
n-ary version of `-zip`
Thanks!
diff --git a/dash.el b/dash.el
index b91f037..15d1d24 100644
--- a/dash.el
+++ b/dash.el
@@ -818,6 +818,16 @@ of cons cells. Otherwise, return the groupings as a list
of lists. "
(--map (cons (car it) (cadr it)) results)
results)))
+(defun -annotate (fn list)
+ "Returns a list of cons cells where each cell is FN applied to each
+element of LIST paired with the unmodified element of LIST."
+ (-zip (-map fn list) list))
+
+(defmacro --annotate (form list)
+ "Anaphoric version of `-annotate'."
+ (declare (debug (form form)))
+ `(-annotate (lambda (it) ,form) ,list))
+
(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/dev/examples.el b/dev/examples.el
index 4042630..836d915 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -439,6 +439,11 @@
(-zip '(1 2 3) '(4 5 6) '(7 8 9)) => '((1 4 7) (2 5 8) (3 6 9))
(-zip '(1 2) '(3 4 5) '(6)) => '((1 3 6)))
+ (defexamples -annotate
+ (-annotate '1+ '(1 2 3)) => '((2 . 1) (3 . 2) (4 . 3))
+ (-annotate 'length '(("h" "e" "l" "l" "o") ("hello" "world"))) => '((5 .
("h" "e" "l" "l" "o")) (2 . ("hello" "world")))
+ (--annotate (< 1 it) '(0 1 2 3)) => '((nil . 0) (nil . 1) (t . 2) (t . 3)))
+
(defexamples -first
(-first 'even? '(1 2 3)) => 2
(-first 'even? '(1 3 5)) => nil
diff --git a/readme-template.md b/readme-template.md
index d3eecb0..ae51a32 100644
--- a/readme-template.md
+++ b/readme-template.md
@@ -174,7 +174,7 @@ Change `readme-template.md` or `examples-to-docs.el`
instead.
- [Emanuel Evans](https://github.com/shosti) contributed `-if-let`,
`-when-let` and `-insert-at`.
- [Johan Andersson](https://github.com/rejeep) contributed `-sum`, `-product`
and `-same-items?`
- [Christina Whyte](https://github.com/kurisuwhyte) contributed `-compose`
- - [Steve Lamb](https://github.com/steventlamb) contributed an n-ary version
of `-zip`
+ - [Steve Lamb](https://github.com/steventlamb) contributed `-annotate` and an
n-ary version of `-zip`
Thanks!
- [elpa] externals/dash f5264db 291/439: Merge pull request #77 from Fuco1/split-when, (continued)
- [elpa] externals/dash f5264db 291/439: Merge pull request #77 from Fuco1/split-when, Phillip Lord, 2015/08/04
- [elpa] externals/dash 5086d24 293/439: Merge pull request #60 from rejeep/cask, Phillip Lord, 2015/08/04
- [elpa] externals/dash 43dcd37 295/439: Only eval NUM in --dotimes once, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4e6a965 294/439: Still better debug declarations, Phillip Lord, 2015/08/04
- [elpa] externals/dash 703bb59 297/439: Convert -zip to support variable-length arguments, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4ecfea6 296/439: Merge pull request #79 from Fuco1/debug-forms, Phillip Lord, 2015/08/04
- [elpa] externals/dash c08fcba 299/439: Fixed documentation of `-last-item'., Phillip Lord, 2015/08/04
- [elpa] externals/dash c952a54 300/439: Merge pull request #90 from tmalsburg/last-item-doc, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2dfd748 298/439: Merge pull request #87 from steventlamb/topic/make_zip_n_ary, Phillip Lord, 2015/08/04
- [elpa] externals/dash bd85b7c 302/439: Make -zip support infinite (circular) lists, Phillip Lord, 2015/08/04
- [elpa] externals/dash f0dd4cc 301/439: Add -annotate,
Phillip Lord <=
- [elpa] externals/dash f780322 305/439: Add `-flatten-n`, Phillip Lord, 2015/08/04
- [elpa] externals/dash fb51f8f 304/439: Merge pull request #88 from steventlamb/topic/zip_cycle_pad, Phillip Lord, 2015/08/04
- [elpa] externals/dash 00549e4 307/439: Add missing fontification keywords, Phillip Lord, 2015/08/04
- [elpa] externals/dash cd137e0 310/439: `-slice` should not fill the returned list with nils if to > length, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6b64ea7 303/439: Add functions for flexibly zipping uneven lists, Phillip Lord, 2015/08/04
- [elpa] externals/dash 63ec298 308/439: Merge pull request #92 from Fuco1/outer-product, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7185db8 311/439: [Issue #83] Add `step` to `-slice`, Phillip Lord, 2015/08/04
- [elpa] externals/dash a3021eb 313/439: Merge pull request #93 from lunaryorn/patch-1, Phillip Lord, 2015/08/04
- [elpa] externals/dash 624c501 306/439: Add `-table` and `-table-flat`, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0384eee 312/439: Improve Travis CI configuration, Phillip Lord, 2015/08/04