commit
58ebe4efec
@ -138,6 +138,32 @@ Return True if ``coll`` is empty, i.e. ``(= 0 (len coll))``.
|
||||
False
|
||||
|
||||
|
||||
.. _every?-fn:
|
||||
|
||||
every?
|
||||
------
|
||||
|
||||
.. versionadded:: 0.9.13
|
||||
|
||||
Usage: ``(every? pred coll)``
|
||||
|
||||
Return True if ``(pred x)`` is logical true for every ``x`` in ``coll``, otherwise False. Return True if ``coll`` is empty.
|
||||
|
||||
.. code-block:: clojure
|
||||
|
||||
=> (every? even? [2 4 6])
|
||||
True
|
||||
|
||||
=> (every? even? [1 3 5])
|
||||
False
|
||||
|
||||
=> (every? even? [2 4 5])
|
||||
False
|
||||
|
||||
=> (every? even? [])
|
||||
True
|
||||
|
||||
|
||||
.. _float?-fn:
|
||||
|
||||
float?
|
||||
@ -570,6 +596,32 @@ Return the second member of ``coll``. Equivalent to
|
||||
1
|
||||
|
||||
|
||||
.. _some-fn:
|
||||
|
||||
some
|
||||
----
|
||||
|
||||
.. versionadded:: 0.9.13
|
||||
|
||||
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.
|
||||
|
||||
.. code-block:: clojure
|
||||
|
||||
=> (some even? [2 4 6])
|
||||
True
|
||||
|
||||
=> (some even? [1 3 5])
|
||||
False
|
||||
|
||||
=> (some even? [1 3 6])
|
||||
True
|
||||
|
||||
=> (some even? [])
|
||||
False
|
||||
|
||||
|
||||
.. _string?-fn:
|
||||
|
||||
string?
|
||||
|
@ -108,6 +108,10 @@
|
||||
(_numeric-check n)
|
||||
(= (% n 2) 0))
|
||||
|
||||
(defn every? [pred coll]
|
||||
"Return true if (pred x) is logical true for every x in coll, else false"
|
||||
(all (map pred coll)))
|
||||
|
||||
(defn fake-source-positions [tree]
|
||||
"Fake the source positions for a given tree"
|
||||
(if (and (iterable? tree) (not (string? tree)))
|
||||
@ -294,6 +298,10 @@
|
||||
"Return second item from `coll`"
|
||||
(get 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)))
|
||||
|
||||
(defn string [x]
|
||||
"Cast x as current string implementation"
|
||||
(if-python2
|
||||
@ -338,9 +346,9 @@
|
||||
(= n 0))
|
||||
|
||||
(def *exports* '[calling-module-name coll? cons cons? cycle dec distinct
|
||||
disassemble drop drop-while empty? even? first filter
|
||||
disassemble drop drop-while empty? even? every? first filter
|
||||
flatten float? gensym identity inc instance? integer
|
||||
integer? integer-char? iterable? iterate iterator?
|
||||
list* macroexpand macroexpand-1 neg? nil? none? nth
|
||||
numeric? odd? pos? remove repeat repeatedly rest second
|
||||
string string? take take-nth take-while zero?])
|
||||
some string string? take take-nth take-while zero?])
|
||||
|
@ -123,6 +123,13 @@
|
||||
(try (even? None)
|
||||
(catch [e [TypeError]] (assert (in "not a number" (str e))))))
|
||||
|
||||
(defn test-every? []
|
||||
"NATIVE: testing the every? function"
|
||||
(assert-true (every? even? [2 4 6]))
|
||||
(assert-false (every? even? [1 3 5]))
|
||||
(assert-false (every? even? [2 4 5]))
|
||||
(assert-true (every? even? [])))
|
||||
|
||||
(defn test-filter []
|
||||
"NATIVE: testing the filter function"
|
||||
(setv res (list (filter pos? [ 1 2 3 -4 5])))
|
||||
@ -399,6 +406,13 @@
|
||||
(assert-equal 2 (second [1 2]))
|
||||
(assert-equal 3 (second [2 3 4])))
|
||||
|
||||
(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? [])))
|
||||
|
||||
(defn test-string? []
|
||||
"NATIVE: testing string?"
|
||||
(assert-true (string? "foo"))
|
||||
@ -456,4 +470,3 @@
|
||||
(assert-equal res [None None])
|
||||
(setv res (list (take-while (fn [x] (not (none? x))) [1 2 3 4 None 5 6 None 7])))
|
||||
(assert-equal res [1 2 3 4]))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user