Skip to content

Commit

Permalink
Refactorings.
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjos committed Nov 10, 2023
1 parent 11136ee commit 4e26c9e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/org/sbrubbles/conditio.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
([c] (condition c nil))
([id & {:as args}]
(assert (not (nil? id)))
(if (nil? args)
(if (condition? id)
id
{::id id})
(assoc args ::id id))))
(cond (not (nil? args)) (assoc args ::id id)
(condition? id) id
:else {::id id})))

(defn abort
"Throws an exception, taking an optional argument. Also works as a handler."
"Throws an exception, taking an optional argument. The 1-arity version
works as a handler."
([] (abort nil))
([c]
(let [msg (cond (nil? c) "Abort"
Expand All @@ -56,7 +55,7 @@
new handlers.
A handler is a function which takes a condition and returns the value
`signal` should return. A handler chain is a sequence of handlers, to be
`signal` should return. A handler chain is a list of handlers, to be
run one at a time until the first non-`(skip)` value is returned."
{::handler-not-found (list abort)
::restart-not-found (list abort)})
Expand Down Expand Up @@ -139,10 +138,9 @@
[bindings & body]
`(let [merge-handlers# (fn [chain-map# bindings#]
(reduce-kv (fn [acc# k# v#]
(println acc# k# v#)
(if (contains? acc# k#)
(assoc acc# k# (conj (get acc# k#) v#))
(assoc acc# k# (list v# abort))))
(assoc acc# k# (if (contains? acc# k#)
(conj (get acc# k#) v#)
(list v# abort))))
chain-map#
bindings#))]
(binding [*handlers* (merge-handlers# *handlers* (hash-map ~@bindings))]
Expand Down

0 comments on commit 4e26c9e

Please sign in to comment.