]> code.delx.au - gnu-emacs/commitdiff
Improve the semantic of map-some
authorNicolas Petton <nicolas@petton.fr>
Sat, 5 Sep 2015 22:51:35 +0000 (00:51 +0200)
committerNicolas Petton <nicolas@petton.fr>
Sat, 5 Sep 2015 22:51:35 +0000 (00:51 +0200)
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.

lisp/emacs-lisp/map.el
test/automated/map-tests.el

index 4e7d3b91b16019fa41e090ae440af73d247895f4..ea56efefe97529f4c8cb8a48b7338ad6c8a6734d 100644 (file)
@@ -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))
 
index ca680041944e8fa440f6eefbf8e4decd69d79002..8693415a784cbae66414a9f1fca8285dbfb360e7 100644 (file)
@@ -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