Bad*_*ild 0 clojure anonymous-function
一个简单的例子应该证明我的问题:
First I define a simple variable:
(def a '(["one" 1] ["two" 2] ["nine" 9]))
;; CASE 1: (This works correctly)
(take-while #(< (second %) 5) a)
Returns: (["one" 1] ["two" 2])
;; CASE 2: (This does not seem to work correctly)
;; The only difference is the '>' instead of '<'
(take-while #(> (second %) 5) a)
Returns: ()
Run Code Online (Sandbox Code Playgroud)
在我看来CASE 2应该返回(["9"9])?
有没有办法调试这个,看看我错过了什么?
谢谢!
take-while在第一次测试失败后停止.由于第一个元素未通过测试(不超过五个),因此它永远不会到达最后一个元素.如果您希望所有通过测试的元素无论它们出现在序列中的哪个位置,请filter改用.