summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Petton <nicolas@petton.fr>2015-09-06 00:51:35 +0200
committerNicolas Petton <nicolas@petton.fr>2015-09-06 00:51:35 +0200
commit1b5fda5cbca96aec3e407bc9e4f8a16e48e7954c (patch)
treed85433211e2e19cf00ea34a4b06db3ef1e4c49e6
parenta1535f938181ea137037d0233924a2c9d9e08f76 (diff)
downloademacs-1b5fda5cbca96aec3e407bc9e4f8a16e48e7954c.tar.gz
Improve the semantic of map-some
Update map-some to return the returned by the predicate, similar to seq-some. * lisp/emacs-lisp/map.el (map-some): Update the function to return the return value of the predicate. * test/automated/map-tests.el (test-map-some): Update the test to check for non-nil values only.
-rw-r--r--lisp/emacs-lisp/map.el5
-rw-r--r--test/automated/map-tests.el26
2 files changed, 15 insertions, 16 deletions
diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el
index 4e7d3b91b16..ea56efefe97 100644
--- a/lisp/emacs-lisp/map.el
+++ b/lisp/emacs-lisp/map.el
@@ -262,8 +262,9 @@ MAP can be a list, hash-table or array."
MAP can be a list, hash-table or array."
(catch 'map--break
(map-apply (lambda (key value)
- (when (funcall pred key value)
- (throw 'map--break (cons key value))))
+ (let ((result (funcall pred key value)))
+ (when result
+ (throw 'map--break result))))
map)
nil))
diff --git a/test/automated/map-tests.el b/test/automated/map-tests.el
index ca680041944..8693415a784 100644
--- a/test/automated/map-tests.el
+++ b/test/automated/map-tests.el
@@ -262,21 +262,19 @@ Evaluate BODY for each created map.
(ert-deftest test-map-some ()
(with-maps-do map
- (should (equal (map-some (lambda (k _v)
- (eq 1 k))
- map)
- (cons 1 4)))
- (should (not (map-some (lambda (k _v)
- (eq 'd k))
- map))))
+ (should (map-some (lambda (k _v)
+ (eq 1 k))
+ map))
+ (should-not (map-some (lambda (k _v)
+ (eq 'd k))
+ map)))
(let ((vec [a b c]))
- (should (equal (map-some (lambda (k _v)
- (> k 1))
- vec)
- (cons 2 'c)))
- (should (not (map-some (lambda (k _v)
- (> k 3))
- vec)))))
+ (should (map-some (lambda (k _v)
+ (> k 1))
+ vec))
+ (should-not (map-some (lambda (k _v)
+ (> k 3))
+ vec))))
(ert-deftest test-map-every-p ()
(with-maps-do map