diff options
| -rw-r--r-- | README.org | 16 | ||||
| -rw-r--r-- | core.fnl | 7 |
2 files changed, 18 insertions, 5 deletions
@@ -482,13 +482,11 @@ These are commonly used so it makes sense to have that, without defining via ano Other predicates are self-explanatory: -- =any?= - =assoc?= - =boolean?= - =double?= - =empty?= - =even?= -- =every?= - =false?= - =int?= - =neg?= @@ -499,9 +497,9 @@ Other predicates are self-explanatory: - =true?= - =zero?= -** =eq?= +** =eq= Deep compare values. -If given two tables, recursively calls =eq?= on each field until one of the tables exhausted. +If given two tables, recursively calls =eq= on each field until one of the tables exhausted. Other values are compared with default equality operator. ** =comp= @@ -519,6 +517,16 @@ Compose functions into one function. # LocalWords: namespaces defmulti defmethod metamethod butlast # LocalWords: prepend LocalWords docstring +** =every?= and =not-any?= +=every?= checks if predicate is true for every item in the table. +=not-any?= checks if predicate is false foe every item in the table. + +#+begin_src fennel + >> (every? pos-int? [1 2 3 4]) + true + >> (not-any? pos-int? [-1 -2 -3 4.2]) + true +#+end_src * Footnotes [fn:1] https://todo.sr.ht/~technomancy/fennel/18#event-56799 @@ -380,17 +380,22 @@ ignored. Returns a table of results." (reduce comp (consj fs g f)))) (fn* core.every? + "Test if every item in `tbl' satisfies the `pred'." [pred tbl] (if (empty? tbl) true (pred (. tbl 1)) (every? pred [(unpack tbl 2)]) false)) (fn* core.some + "Test if any item in `tbl' satisfies the `pred'." [pred tbl] (when-let [tbl (seq tbl)] (or (pred (. tbl 1)) (some pred [(unpack tbl 2)])))) -(set core.not-any? (comp #(not $) some)) +(set core.not-any? + (with-meta (comp #(not $) some) + {:fnl/docstring "Test if no item in `tbl' satisfy the `pred'." + :fnl/arglist ["pred" "tbl"]})) (fn& core.complement "Takes a function `f' and returns the function that takes the same |