Quantoga
Quantoga -- Algorithmic trading and investment systems; ideas, research and development.
Sunday, December 23, 2018
Clojure quick tip: efficiently find last element in vector satisfying some condition
Trivial, but I keep forgetting about
rseq
:
user> (first (
filter
#(even? (do (println "x:" %) %))
(
rseq
(
vec
(range 1 100)))))
x: 99
x: 98
98
user>
Vec
is very nice; it'll alias JVM arrays. Anyway, doing
(last (filter ..))
would traverse the entire vector which isn't very effective.
PS: Merry XMAS. :)
No comments:
Post a Comment
Newer Post
Older Post
Home
No comments:
Post a Comment