What is the rule behind the following behavior:
user=> (take-while #(> 10 %) [2 9 4 12 3 99])
(2 9 4)
user=> (take-while #(> % 10) [2 9 4 12 3 99])
()
Thanks!
There is a pretty big difference between "Is 10 bigger than this number?" and "Is this number bigger than 10?". Those are, respectively, the two predicates you have written, and so of course take-while behaves differently when given each predicate.
Because take-while stops at the first false
(take-while #(> % 10) [2 9 4 12 3 99])
so the very first check is false it then stops and gives you an empty list. This isnt really made clear in https://clojuredocs.org/clojure.core/take-while but its implied for example take
(take-while #(> % 10) [ 11 15 2 9 4 12 3 99])
will output
(11 15)