Fork me on GitHub

There was a discussion in the #clojure channel about condp and the use case for a similar construct that took a unary predicate (instead of a binary predicate and the second argument) but was otherwise identical. Is there an idiomatic way to write that without adding a condq or condp-1 or something to core?


It's easy enough to take a copy of condp and just tweak it to remove every reference to expr and of course you could always do

(condp (fn [t _] (pred t)) :ignored
  v1 r1
  v2 :>> r2-fn)


(there are plenty of ways to work around it... but would a JIRA ticket/patch for this be considered for core?)


I assume this is kind of halfway between cond-> and condp?


It would be identical to condp except for unary predicates (so it would have the :>> behavior etc).


I'm not wedded to it -- just wondering if there's a sufficiently idiomatic alternative really.


Locally (at WS), we already have condp-> and condp->> that work like cond-> and cond->> but thread the expressions through the predicate, and I've often wanted that unary-predicate version of condp -- but ended up reworking it to a longer-form cond (repeating the predicate call in each test expr) or either cond-> or condp-> depending on what I need.


I think I've proposed condp-> and condp->> before and been told "no" 🙂


I see the value and occasionally want something like this. Not sure if it’s worth adding to stdlib


Fair enough. I'll just keep it in our worldsingles.clojure.extensions namespace then. If I see something like it come up elsewhere, I may open a ticket.