Welcome! Please see the About page for a little more info on how this works.

0 votes
in Macros by
After introduction of cond-> and cond->> macros in 1.5. It makes sense to have condp-> and condp->> macros in the core library.

  (condp-> {}
    (complement :a) (assoc :a 1)
    :a (assoc :b 2)) ;=> {:b 2, :a 1}

In the above example the result of each expr which was evaluated is being passed to the next predicate.

4 Answers

0 votes
by

Comment made by: jafingerhut

Kuldeep, I cannot comment on whether this change is of interest to the Clojure developers, because I do not know.

I can say that the patch you have attached is not in the expected format. See the page below for instructions on creating a patch in the expected format:

http://dev.clojure.org/display/community/Developing Patches

0 votes
by

Comment made by: kul

Rebased against master and generated patch as described in wiki.

0 votes
by

Comment made by: vitoshka

This is a very common pattern for me.

This is one way of dealing with such state-dependent conditionals:

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

The proposed condp-> is much more readable:

(-> x (condp-> :foo (assoc :boo 0)) ...)

BTW, condp-> is not exactly the counterpart of condp. So maybe shorter pred-> or p-> are better names for this.

0 votes
by
...