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.
This commit is contained in:
Nicolas Petton 2015-09-06 00:51:35 +02:00
parent a1535f9381
commit 1b5fda5cbc
2 changed files with 15 additions and 16 deletions

View file

@ -262,8 +262,9 @@ MAP can be a list, hash-table or array."
MAP can be a list, hash-table or array." MAP can be a list, hash-table or array."
(catch 'map--break (catch 'map--break
(map-apply (lambda (key value) (map-apply (lambda (key value)
(when (funcall pred key value) (let ((result (funcall pred key value)))
(throw 'map--break (cons key value)))) (when result
(throw 'map--break result))))
map) map)
nil)) nil))

View file

@ -262,21 +262,19 @@ Evaluate BODY for each created map.
(ert-deftest test-map-some () (ert-deftest test-map-some ()
(with-maps-do map (with-maps-do map
(should (equal (map-some (lambda (k _v) (should (map-some (lambda (k _v)
(eq 1 k)) (eq 1 k))
map) map))
(cons 1 4))) (should-not (map-some (lambda (k _v)
(should (not (map-some (lambda (k _v) (eq 'd k))
(eq 'd k)) map)))
map))))
(let ((vec [a b c])) (let ((vec [a b c]))
(should (equal (map-some (lambda (k _v) (should (map-some (lambda (k _v)
(> k 1)) (> k 1))
vec) vec))
(cons 2 'c))) (should-not (map-some (lambda (k _v)
(should (not (map-some (lambda (k _v) (> k 3))
(> k 3)) vec))))
vec)))))
(ert-deftest test-map-every-p () (ert-deftest test-map-every-p ()
(with-maps-do map (with-maps-do map