Is there a better way than the following:
(defn in-interval?
"Returns a predicate that tests if its argument falls in
the inclusive interval [a, b]."
[a b]
(fn [x] (and (>= x a) (<= x b))))
In use:
((in-interval? 5 8) 5.5) ; true
((in-interval? 5 8) 9) ; false
I don't want to use range
, for example, because that constructs a lazy sequence.
Is there a better way than the following:
Yes.
(<= 5 8 8.5)
It works with any number of arguments and check if they are ordered. With 3 arguments, it's what you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With