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:
|
||||
|
@ -26,7 +26,7 @@
|
||||
(import itertools)
|
||||
(import functools)
|
||||
(import collections)
|
||||
(import sys)
|
||||
(import sys)
|
||||
(import [hy._compat [long-type]]) ; long for python2, int for python3
|
||||
(import [hy.models.cons [HyCons]])
|
||||
(import [hy.lex [LexException PrematureEndOfInput tokenize]])
|
||||
@ -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"
|
||||
@ -347,7 +347,7 @@
|
||||
(setv buff (+ buff inn))
|
||||
(try
|
||||
(def parsed (first (tokenize buff)))
|
||||
(except [e [LexException PrematureEndOfInput IndexError]])
|
||||
(except [e [LexException PrematureEndOfInput IndexError]])
|
||||
(else (if parsed (break)))))
|
||||
parsed)
|
||||
|
||||
|
@ -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