[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash e574465 404/439: Add `-some`
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash e574465 404/439: Add `-some` |
Date: |
Tue, 04 Aug 2015 20:31:16 +0000 |
branch: externals/dash
commit e574465eddae6d07b68b508f29baca126bfca701
Author: Vasilij Schneidermann <address@hidden>
Commit: Vasilij Schneidermann <address@hidden>
Add `-some`
This is a port of the CL function `some` and the Scheme function `any`
from SRFI-1. It is thought as addition to `-any?` (which returns a
boolean) and `-first` (which returns an element). Unlike these it
returns the first truthy value of applying the predicate on each list
item.
Resolves #122.
---
README.md | 13 +++++++++++++
dash.el | 22 ++++++++++++++++++++++
dev/examples.el | 5 +++++
3 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index 91f0799..8cac2de 100644
--- a/README.md
+++ b/README.md
@@ -180,6 +180,7 @@ Other list functions not fit to be classified elsewhere.
* [-table](#-table-fn-rest-lists) `(fn &rest lists)`
* [-table-flat](#-table-flat-fn-rest-lists) `(fn &rest lists)`
* [-first](#-first-pred-list) `(pred list)`
+* [-some](#-some-pred-list) `(pred list)`
* [-last](#-last-pred-list) `(pred list)`
* [-first-item](#-first-item-list) `(list)`
* [-last-item](#-last-item-list) `(list)`
@@ -1409,6 +1410,18 @@ Alias: `-find`
(--first (> it 2) '(1 2 3)) ;; => 3
```
+#### -some `(pred list)`
+
+Return (`pred` x) for the first `list` item where (`pred` x) is non-nil, else
nil.
+
+Alias: `-any`
+
+```el
+(-some 'even? '(1 2 3)) ;; => t
+(--some (member 'foo it) '((foo bar) (baz))) ;; => '(foo bar)
+(--some (plist-get it :bar) '((:foo 1 :bar 2) (:baz 3))) ;; => 2
+```
+
#### -last `(pred list)`
Return the last x in `list` where (`pred` x) is non-nil, else nil.
diff --git a/dash.el b/dash.el
index 60596f4..d3721e3 100644
--- a/dash.el
+++ b/dash.el
@@ -391,6 +391,24 @@ Alias: `-find'"
(defalias '-find '-first)
(defalias '--find '--first)
+(defmacro --some (form list)
+ "Anaphoric form of `-some'."
+ (declare (debug (form form)))
+ (let ((n (make-symbol "needle")))
+ `(let (,n)
+ (--each-while ,list (not ,n)
+ (setq ,n ,form))
+ ,n)))
+
+(defun -some (pred list)
+ "Return (PRED x) for the first LIST item where (PRED x) is non-nil, else nil.
+
+Alias: `-any'"
+ (--some (funcall pred it) list))
+
+(defalias '-any '-some)
+(defalias '--any '--some)
+
(defmacro --last (form list)
"Anaphoric form of `-last'."
(declare (debug (form form)))
@@ -1991,6 +2009,10 @@ structure such as plist or alist."
"--first"
"-find"
"--find"
+ "-some"
+ "--some"
+ "-any"
+ "--any"
"-last"
"--last"
"-first-item"
diff --git a/dev/examples.el b/dev/examples.el
index 79ac244..40e177c 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -546,6 +546,11 @@ new list."
(-first 'even? '(1 3 5)) => nil
(--first (> it 2) '(1 2 3)) => 3)
+ (defexamples -some
+ (-some 'even? '(1 2 3)) => t
+ (--some (member 'foo it) '((foo bar) (baz))) => '(foo bar)
+ (--some (plist-get it :bar) '((:foo 1 :bar 2) (:baz 3))) => 2)
+
(defexamples -last
(-last 'even? '(1 2 3 4 5 6 3 3 3)) => 6
(-last 'even? '(1 3 7 5 9)) => nil
- [elpa] externals/dash 70caa37 432/439: Merge pull request #144 from cammsaul/thread_last_make_second_arg_optional, (continued)
- [elpa] externals/dash 70caa37 432/439: Merge pull request #144 from cammsaul/thread_last_make_second_arg_optional, Phillip Lord, 2015/08/04
- [elpa] externals/dash 1677338 428/439: Merge pull request #138 from phillord/fix/group-by-write-out, Phillip Lord, 2015/08/04
- [elpa] externals/dash e468937 435/439: Formatting, Phillip Lord, 2015/08/04
- [elpa] externals/dash 89abffe 437/439: Make it explicit that not all VALS are evalled in -if-let*, Phillip Lord, 2015/08/04
- [elpa] externals/dash b88cfb7 436/439: Add dash prefix to epsilon variable., Phillip Lord, 2015/08/04
- [elpa] externals/dash eadb265 439/439: Swap examples to better show how -some-> works, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2aeeacb 433/439: Release 2.11.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash c3cf98d 438/439: Add `-some->`, `-some->>`, and `-some-->` macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash 1c2f43d 434/439: Add "See also" for the reduce family, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2b69c14 411/439: Add dash.info and dash.texi to repo, Phillip Lord, 2015/08/04
- [elpa] externals/dash e574465 404/439: Add `-some`,
Phillip Lord <=
- [elpa] externals/dash 4640a2a 405/439: Allow for approx comparison of floats in tests, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3b63476 412/439: Move anaphoric function intro up into Functions section, Phillip Lord, 2015/08/04
- [elpa] externals/dash 19fbc24 426/439: Fix anaphoric -spice-list macro, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2db56f5 424/439: [-let] Add support for &as bindings (#115), Phillip Lord, 2015/08/04
- [elpa] externals/dash ffa37bf 425/439: Merge pull request #129 from holomorph/docs, Phillip Lord, 2015/08/04
- [elpa] externals/dash 81b808d 409/439: Ignore dash.elc, Phillip Lord, 2015/08/04
- [elpa] externals/dash c61113b 420/439: [-let] Update outdated comment, Phillip Lord, 2015/08/04
- [elpa] externals/dash 733274f 398/439: Merge pull request #120 from holomorph/info-manual, Phillip Lord, 2015/08/04
- [elpa] externals/dash a803dd5 414/439: Merge readme changes, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7bd6b3b 400/439: Add dir entry to texinfo template, Phillip Lord, 2015/08/04