Created
November 20, 2015 00:12
-
-
Save jhalterman/f361d57da42571a85469 to your computer and use it in GitHub Desktop.
Try until success
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn try-until-success | |
"Accepts a try-fn to try a failure-fn to call upon failure, supplying the failure/exception. The try-fn is retried | |
until no failure is thrown." | |
[try-fn failure-fn] | |
(loop [] | |
(if-let [result (try | |
(try-fn) | |
(catch Exception e | |
(failure-fn e) | |
nil))] | |
result | |
(recur)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment