Search code examples
clojure

Why is take-while returning empty sequence?


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!


Solution

  • 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.