Merge pull request #649 from microamp/issue-644
Merge master onto pr/649
This commit is contained in:
commit
1c1df745c4
@ -654,21 +654,25 @@ some
|
|||||||
|
|
||||||
Usage: ``(some pred coll)``
|
Usage: ``(some pred coll)``
|
||||||
|
|
||||||
Return True if ``(pred x)`` is logical true for any ``x`` in ``coll``, otherwise False. Return False if ``coll`` is empty.
|
Return the first logical true value of ``(pred x)`` for any ``x`` in
|
||||||
|
``coll``, otherwise ``nil``. Return ``nil`` if ``coll`` is empty.
|
||||||
|
|
||||||
.. code-block:: hy
|
.. code-block:: hy
|
||||||
|
|
||||||
=> (some even? [2 4 6])
|
=> (some even? [2 4 6])
|
||||||
True
|
True
|
||||||
|
|
||||||
=> (some even? [1 3 5])
|
=> (nil? (some even? [1 3 5]))
|
||||||
False
|
|
||||||
|
|
||||||
=> (some even? [1 3 6])
|
|
||||||
True
|
True
|
||||||
|
|
||||||
=> (some even? [])
|
=> (nil? (some identity [0 "" []]))
|
||||||
False
|
True
|
||||||
|
|
||||||
|
=> (some identity [0 "non-empty-string" []])
|
||||||
|
'non-empty-string'
|
||||||
|
|
||||||
|
=> (nil? (some even? []))
|
||||||
|
True
|
||||||
|
|
||||||
|
|
||||||
.. _string?-fn:
|
.. _string?-fn:
|
||||||
|
@ -299,8 +299,8 @@
|
|||||||
(nth coll 1))
|
(nth coll 1))
|
||||||
|
|
||||||
(defn some [pred coll]
|
(defn some [pred coll]
|
||||||
"Return true if (pred x) is logical true for any x in coll, else false"
|
"Return the first logical true value of (pred x) for any x in coll, else nil"
|
||||||
(any (map pred coll)))
|
(first (filter nil (map pred coll))))
|
||||||
|
|
||||||
(defn string [x]
|
(defn string [x]
|
||||||
"Cast x as current string implementation"
|
"Cast x as current string implementation"
|
||||||
|
@ -474,9 +474,16 @@
|
|||||||
(defn test-some []
|
(defn test-some []
|
||||||
"NATIVE: testing the some function"
|
"NATIVE: testing the some function"
|
||||||
(assert-true (some even? [2 4 6]))
|
(assert-true (some even? [2 4 6]))
|
||||||
(assert-false (some even? [1 3 5]))
|
(assert-nil (some even? [1 3 5]))
|
||||||
(assert-true (some even? [1 3 6]))
|
(assert-true (some even? [1 2 3]))
|
||||||
(assert-false (some even? [])))
|
(assert-nil (some even? []))
|
||||||
|
; 0, "" (empty string) and [] (empty list) are all logical false
|
||||||
|
(assert-nil (some identity [0 "" []]))
|
||||||
|
; non-empty string is logical true
|
||||||
|
(assert-equal (some identity [0 "this string is non-empty" []])
|
||||||
|
"this string is non-empty")
|
||||||
|
; nil if collection is empty
|
||||||
|
(assert-nil (some even? [])))
|
||||||
|
|
||||||
(defn test-string? []
|
(defn test-string? []
|
||||||
"NATIVE: testing string?"
|
"NATIVE: testing string?"
|
||||||
|
Loading…
Reference in New Issue
Block a user