plumatic / plumbing

Prismatic's Clojure(Script) utility belt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Functional versions of ?> and ?>>

vspinu opened this issue · comments

Would be nice to have conditionals on predicates on the current value of the pipilined object.

So instead of

(-> x
   (as-> y (if (:foo y) (assoc y :boo 0) y))

have

(-> x
    (??> :foo (assoc :boo 0))

This is the most common pattern for me. I almost always need a conditional that is dependent on the current value of the object.

Thanks for the suggestion! But I think we probably don't want to get any deeper into the arrows game. The existing ones should probably be deprecated now that cond-> is in core.

cond-> surely fills the shoes of ?> but it doesn't address the pattern of ??> that I was proposing.

But I think we probably don't want to get any deeper into the arrows game.

Sorry for bugging, but any specific reason behind this? What's wrong with arrows?

There is a jira ticket for condp-> here. Not much attention so far though.

Nothing wrong with arrows, Iove and use them a lot. I just meant that there are a wide variety of additional arrow proposals I've seen on the mailing list and elsewhere, e.g.

https://github.com/rplevy/swiss-arrows

(i'm not sure how serious this one is). Moreover, the goal of plumbing.core is to be the things we wish were in Clojure.core (which is meant to be a pretty high bar).

In my experience, when a situation comes up that breaks the arrow, it's not too bad to either just use an anonymous function for the step, or just break up the arrow. I'm not sure that any more new syntax is really needed / justified for working with arrows, and that's what I meant above.