When writing code that needs to do predicate dispatch (such as code analysis libraries), it's quite common to need an invoke
function for a pattern that looks like:
`
(defn classify [x]
(condp invoke x
string? (string-f x ..)
number? (number-f x ..)
..))
`
This is definitely expressible without invoke
, but the condp invoke
pattern reads quite nicely.
Additionally invoke
is also useful in the cases where one has a sliding window of functions and values, for patterns like:
(apply map invoke funs vals)
Patch: 0001-CLJ-2342-add-invoke.patch