I tried to do the following in Clojure
(map future exprs)
To get a seq of future tokens. Unfortunately this errs because future
is itself a macro, not a function.
Is there a way to make this work while still maintaining the map
syntax? I'd rather not use the for
macro (just as a matter of personal style).
I suppose I'm looking for a mmap
or macro map.
As already stated by Marcin, use a lambda (anonymous function)
user=> (map and [true false 0 nil])
java.lang.Exception: Can't take value of a macro: #'clojure.core/and (NO_SOURCE_FILE:1)
user=> (map #(and %) [true false 0 nil])
(true false 0 nil)
edit
By the way, if you're using map
to create a bunch of tasks to be executed in other threads, you might have issues. map
is lazy, and the futures won't be created until something asks for them. You would need to force it to be evaluated (which is what happens in the repl when the repl prints the result) or find some other way.
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