Skip to content

Commit 4d83e2c

Browse files
Vadim PlatonovVadim Platonov
authored andcommitted
conversion: allow idempotent conversion!
1 parent f97ea94 commit 4d83e2c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/java_time/defconversion.clj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
;; currently we just incur a 0.5*number of types dropped penalty
3535
(+ cost (* 0.5 (- (count xs) (count combo)))))))))
3636

37+
(def ^:dynamic *fail-on-duplicate-conversion?* true)
38+
3739
(defn conversion!
3840
([from to f] (conversion! from to f 1))
3941
([from-type-vec to-type-vec f cost]
@@ -43,8 +45,9 @@
4345
(swap! graph
4446
(fn [g]
4547
(if-let [existing (g/get-conversion g from to)]
46-
(throw (ex-info (format "Conversion %s -> %s already exists: %s!" from to existing)
47-
{:from from, :to to, :existing existing}))
48+
(when *fail-on-duplicate-conversion?*
49+
(throw (ex-info (format "Conversion %s -> %s already exists: %s!" from to existing)
50+
{:from from, :to to, :existing existing})))
4851
(let [f (wrap-validation from to f)]
4952
(g/assoc-conversion g from to f cost)))))))))
5053

0 commit comments

Comments
 (0)