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)``
|
||||
|
||||
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
|
||||
|
||||
=> (some even? [2 4 6])
|
||||
True
|
||||
|
||||
=> (some even? [1 3 5])
|
||||
False
|
||||
|
||||
=> (some even? [1 3 6])
|
||||
=> (nil? (some even? [1 3 5]))
|
||||
True
|
||||
|
||||
=> (some even? [])
|
||||
False
|
||||
=> (nil? (some identity [0 "" []]))
|
||||
True
|
||||
|
||||
=> (some identity [0 "non-empty-string" []])
|
||||
'non-empty-string'
|
||||
|
||||
=> (nil? (some even? []))
|
||||
True
|
||||
|
||||
|
||||
.. _string?-fn:
|
||||
|
@ -299,8 +299,8 @@
|
||||
(nth coll 1))
|
||||
|
||||
(defn some [pred coll]
|
||||
"Return true if (pred x) is logical true for any x in coll, else false"
|
||||
(any (map pred coll)))
|
||||
"Return the first logical true value of (pred x) for any x in coll, else nil"
|
||||
(first (filter nil (map pred coll))))
|
||||
|
||||
(defn string [x]
|
||||
"Cast x as current string implementation"
|
||||
|
@ -474,9 +474,16 @@
|
||||
(defn test-some []
|
||||
"NATIVE: testing the some function"
|
||||
(assert-true (some even? [2 4 6]))
|
||||
(assert-false (some even? [1 3 5]))
|
||||
(assert-true (some even? [1 3 6]))
|
||||
(assert-false (some even? [])))
|
||||
(assert-nil (some even? [1 3 5]))
|
||||
(assert-true (some even? [1 2 3]))
|
||||
(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? []
|
||||
"NATIVE: testing string?"
|
||||
|
Loading…
Reference in New Issue
Block a user