[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash e574465 404/426: Add `-some`
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash e574465 404/426: Add `-some` |
Date: |
Tue, 04 Aug 2015 19:39:14 +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 3992e3c 406/426: Make `-fixfn' more robust at handling floats, (continued)
- [elpa] externals/dash 3992e3c 406/426: Make `-fixfn' more robust at handling floats, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4bd6273 397/426: Invoke makeinfo on the generated .texi, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7d62b1a 393/426: Make test suite independent of dash, Phillip Lord, 2015/08/04
- [elpa] externals/dash 92ed7ff 391/426: Use vendored ert only on emacs23, Phillip Lord, 2015/08/04
- [elpa] externals/dash 07f0358 392/426: Add test case operator !!> for expected errors, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0ef7384 395/426: Merge pull request #114 from fbergroth/update-test-case, Phillip Lord, 2015/08/04
- [elpa] externals/dash 26c1bbe 390/426: Merge pull request #113 from fbergroth/fix-byte-compile-test, Phillip Lord, 2015/08/04
- [elpa] externals/dash c34e4ab 394/426: Update invalid tests, Phillip Lord, 2015/08/04
- [elpa] externals/dash 349931e 399/426: Add @holomorph to list of contributors, Phillip Lord, 2015/08/04
- [elpa] externals/dash 1ccd2b4 389/426: Improve byte compilation test, Phillip Lord, 2015/08/04
- [elpa] externals/dash e574465 404/426: Add `-some`,
Phillip Lord <=
- [elpa] externals/dash 4640a2a 405/426: Allow for approx comparison of floats in tests, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3a3f528 396/426: Add info manual, Phillip Lord, 2015/08/04