aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Petton2015-09-06 00:51:35 +0200
committerNicolas Petton2015-09-06 00:51:35 +0200
commit1b5fda5cbca96aec3e407bc9e4f8a16e48e7954c (patch)
treed85433211e2e19cf00ea34a4b06db3ef1e4c49e6
parenta1535f938181ea137037d0233924a2c9d9e08f76 (diff)
downloademacs-1b5fda5cbca96aec3e407bc9e4f8a16e48e7954c.tar.gz
emacs-1b5fda5cbca96aec3e407bc9e4f8a16e48e7954c.zip
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."
262MAP can be a list, hash-table or array." 262MAP can be a list, hash-table or array."
263 (catch 'map--break 263 (catch 'map--break
264 (map-apply (lambda (key value) 264 (map-apply (lambda (key value)
265 (when (funcall pred key value) 265 (let ((result (funcall pred key value)))
266 (throw 'map--break (cons key value)))) 266 (when result
267 (throw 'map--break result))))
267 map) 268 map)
268 nil)) 269 nil))
269 270
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.
262 262
263(ert-deftest test-map-some () 263(ert-deftest test-map-some ()
264 (with-maps-do map 264 (with-maps-do map
265 (should (equal (map-some (lambda (k _v) 265 (should (map-some (lambda (k _v)
266 (eq 1 k)) 266 (eq 1 k))
267 map) 267 map))
268 (cons 1 4))) 268 (should-not (map-some (lambda (k _v)
269 (should (not (map-some (lambda (k _v) 269 (eq 'd k))
270 (eq 'd k)) 270 map)))
271 map))))
272 (let ((vec [a b c])) 271 (let ((vec [a b c]))
273 (should (equal (map-some (lambda (k _v) 272 (should (map-some (lambda (k _v)
274 (> k 1)) 273 (> k 1))
275 vec) 274 vec))
276 (cons 2 'c))) 275 (should-not (map-some (lambda (k _v)
277 (should (not (map-some (lambda (k _v) 276 (> k 3))
278 (> k 3)) 277 vec))))
279 vec)))))
280 278
281(ert-deftest test-map-every-p () 279(ert-deftest test-map-every-p ()
282 (with-maps-do map 280 (with-maps-do map