Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

composition arrows #24

Open
neapel opened this issue May 21, 2014 · 2 comments
Open

composition arrows #24

neapel opened this issue May 21, 2014 · 2 comments

Comments

@neapel
Copy link

neapel commented May 21, 2014

I'm quite new to clojure and not sure if there isn't a better way already, but I found myself writing things like

(fn [x] (->> x (f a) (g b)))

quite often. Which I instinctively want to write in a point-free style, but this means I'll loose the comfort and readability of arrows:

(comp (partial g b) (partial f a))

I'm using these trivial helper macros now:

(defmacro fn->
  "(fn-> f g...) expands to (fn [x] (-> x f g...)"
  [& args]
  `(fn [x#] (-> x# ~@args)))

(defmacro fn->>
  "(fn->> f g...) expands to (fn [x] (->> x f g...))"
  [& args]
  `(fn [x#] (->> x# ~@args)))

which allow writing

(fn->> (f a) (g b))

Would that be a candidate for inclusion in swiss-arrows?

@rplevy
Copy link
Owner

rplevy commented Jul 11, 2014

Did you try the clojure.core/cond-> arrow?

@neapel
Copy link
Author

neapel commented Jul 11, 2014

I don't understand how this would work using cond->? It accepts a value as the first argument like all the other arrows, my idea was about introducing a higher-order arrow that returns a function, which when given a value returns the same result as the other arrows do when given that value as the first argument.

Edit (confused cond-> and condp. There wouldn't be a useful fncond-> version because the clauses would have no way to access the value)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants