This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-21
Channels
- # admin-announcements (14)
- # aws (27)
- # beginners (10)
- # boot (152)
- # cljsrn (3)
- # clojure (93)
- # clojure-hk (4)
- # clojure-russia (35)
- # clojure-switzerland (1)
- # clojurecup (1)
- # clojurescript (146)
- # core-async (23)
- # cursive (2)
- # devcards (1)
- # editors (1)
- # hoplon (28)
- # jobs-rus (4)
- # ldnclj (3)
- # leiningen (3)
- # luminus (2)
- # off-topic (4)
- # om (174)
- # re-frame (1)
- # slack-help (5)
@jethroksy @meikemertsch Not sure where you guys landed, but to add to ian’s response: partial
is idomatic. It does have a more specific use case than #()
and fn
, but that specificity makes it the most appropriate choice when it’s applicable. For example, I would prefer (map (partial str "test") [1 2])
to the alternatives you proposed.
@potetm @meikemertsch @ian to resolve this issue once and for all, the clojure style guide here https://github.com/bbatsov/clojure-style-guide#partial states that the partial version is "arguably better", so I'd say its the accepted idiomatic version, although the reasons were not made clear.
Thank you so much guys
Coming late to this but I generally reach for partial
if I have the first argument(s) and need a function that will apply the remaining argument(s).
So, yes, I'd use (partial str "test")
rather than #(str "test" %)
.
But if the args are anywhere else in the expression you need fn
instead (or #( )
but I generally favor named args and therefore fn
).
I wish we had flip
in core: it takes the last argument(s) and returns a function that takes the remaining (first) argument.
(map (flip / 2.0) [1 2 3])
=> (0.5 1.0 1.5)
since the function is #(/ % 2.0)
did http://4clojure.com literally just go down?