Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aboekhoff/298581 to your computer and use it in GitHub Desktop.
Save aboekhoff/298581 to your computer and use it in GitHub Desktop.
(defn e-bind [f]
(fn [v]
(let [[e *v] (try [true (f v)] (catch Exception e [false (.toString e)]))]
(if e *v (handler e *v f)))))
;; presumably this would do something constructive, and
;; probably expect more preceding state from preceding computations
;; in a domonad form
(defn handler [s x f]
(println "input was" s)
(println "exception was" x)
(println "next fn was " f)
(println (str "... recovering"))
(f #(println :safe-continuation)))
((e-bind #(%)) #(println "foo"))
=>
foo
((e-bind #(%)) nil)
=>
input was false
exception was java.lang.NullPointerException
next fn was #<user$eval__8118$fn__8120 user$eval__8118$fn__8120@7abccf9a>
... recovering
:safe-continuation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment