Fork me on GitHub
#clojure-dev
<
2018-06-05
>
seancorfield20:06:57

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?

seancorfield20:06:41

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)

seancorfield20:06:08

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

alexmiller21:06:17

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

seancorfield21:06:30

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

seancorfield21:06:52

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

seancorfield21:06:48

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.

seancorfield21:06:41

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

alexmiller22:06:48

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

seancorfield22:06:46

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.