Hi there,
I have been trying to shake this thought for a while now. Essentially, my thought was if you can return a function why not decision component of an IF, WHEN or SOME statement? That would give you a re-usable named choice.
Then you could write:
(celebration: do-something do-something-else)
This would be equivalent to writing:
(def success [apples bananas pears])
(defn celebration: [x y] (if (empty? success) x y))
(celebration: (do-something do-something-else))
I'm reasonably certain of the foolishness of this thought but occasionally, I have doubts.
Maybe I'm barking up the wrong tree or possibly I've seen something like this before and forgotten about it. Perhaps, this is just taking things too far... Either way, it's deferring the choice until it's needed. In the right hands it could make for more readable code.
For completeness sake, to define the first form above you'd use:
(defc celebration: (if (empty? success)))
A more usable example might look like:
(def nums [1 2 3 4 5 6 7 8])
(defc even-nums: (some (even? nums)))
I guess this makes the real question, is it a good thing to be able to defer choice like this?
Btw, defc would be like def-choice but other options might be deft - def-test or defp - def-predicate.
--
Kind regards
Stephen