Fork me on GitHub
#beginners
<
2015-11-21
>
potetm14:11:42

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

jethroksy15:11:06

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

meikemertsch15:11:23

Thank you so much guys simple_smile

seancorfield16:11:09

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

seancorfield16:11:15

So, yes, I'd use (partial str "test") rather than #(str "test" %).

seancorfield16:11:40

But if the args are anywhere else in the expression you need fn instead (or #( ) but I generally favor named args and therefore fn).

seancorfield16:11:23

I wish we had flip in core: it takes the last argument(s) and returns a function that takes the remaining (first) argument.

seancorfield16:11:37

(map (flip / 2.0) [1 2 3]) => (0.5 1.0 1.5) since the function is #(/ % 2.0)

swizzard21:11:25

did http://4clojure.com literally just go down?

swizzard21:11:17

nm it’s back