Make Life Simple for Your Callers

It gets even better.

If you know in advance some of the strategies your callers might want to pursue in dealing with an error, you can name those strategies at the point of a possible error, and then let callers select a strategy by name. The bind-continue form takes the name of a strategy, an argument list, and a form to implement the strategy.

So, continuing with our log example, you might choose to provide explicit skip and log strategies for dealing with a parse error:

 (defn parse-or-continue [logseq]
  (let [parse-log-entry
  (fn [entry]
  (with-handler (parse-log-entry entry)
  (bind-continue skip [msg]
  nil)
  (bind-continue log [msg]
  (println "****invalid log: " msg))))]
  (vec (map parse-log-entry ...

Get Functional Programming: A PragPub Anthology now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.