1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-31 23:53:02 +00:00

update any?, every?

Updates `any?` and `every?` to be exact functional analogues to `or` and `and`.
This commit is contained in:
primo-ppcg
2023-08-18 07:39:30 +07:00
parent 43a6a70e1e
commit 15760b0950
2 changed files with 16 additions and 6 deletions

View File

@@ -1424,20 +1424,21 @@
(fn [& r] (f ;more ;r))))
(defn every?
``Returns true if each value in `ind` is truthy, otherwise returns the first
falsey value.``
``Evaluates to the last element of `ind` if all preceding elements are truthy,
otherwise evaluates to the first falsey argument.``
[ind]
(var res true)
(loop [x :in ind :while res]
(if x nil (set res x)))
(set res x))
res)
(defn any?
``Returns the first truthy value in `ind`, otherwise nil.``
``Evaluates to the last element of `ind` if all preceding elements are falsey,
otherwise evaluates to the first truthy element.``
[ind]
(var res nil)
(loop [x :in ind :until res]
(if x (set res x)))
(set res x))
res)
(defn reverse!