Skip to content

Commit

Permalink
Don't use use polymorphic coersion on macro return values
Browse files Browse the repository at this point in the history
  • Loading branch information
niwinz committed Aug 19, 2024
1 parent a546283 commit be4ea19
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/promesa/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,10 @@
[& exprs]
(condp = (count exprs)
0 `(impl/resolved nil)
1 `(pt/-promise ~(first exprs))
1 `(impl/coerce ~(first exprs))
(reduce (fn [acc e]
`(pt/-mcat (pt/-promise ~e) (fn [_#] ~acc)))
`(pt/-promise ~(last exprs))
`(pt/-mcat (impl/coerce ~e) (fn [_#] ~acc)))
`(impl/coerce ~(last exprs))
(reverse (butlast exprs)))))

(defmacro do
Expand All @@ -564,7 +564,7 @@
expression."
[& exprs]
`(pt/-mcat
(pt/-promise nil)
(impl/resolved nil)
(fn [_#]
(promesa.core/do* ~@exprs))))

Expand All @@ -580,7 +580,7 @@
(assert (even? (count bindings)) (str "Uneven binding vector: " bindings))
(c/->> (reverse (partition 2 bindings))
(reduce (fn [acc [l r]]
`(pt/-mcat (pt/-promise ~r) (fn [~l] ~acc)))
`(pt/-mcat (impl/coerce ~r) (fn [~l] ~acc)))
`(do* ~@body))))

(defmacro let
Expand All @@ -589,7 +589,7 @@
[bindings & body]
(if (seq bindings)
`(pt/-mcat
(pt/-promise nil)
(impl/resolved nil)
(fn [_#] (promesa.core/let* ~bindings ~@body)))
`(promesa.core/do ~@body)))

Expand All @@ -599,7 +599,7 @@
[bindings & body]
(assert (even? (count bindings)) (str "Uneven binding vector: " bindings))
`(pt/-mcat
(pt/-promise nil)
(impl/resolved nil)
(fn [_#]
~(c/let [bindings (partition 2 bindings)]
`(c/-> (all ~(mapv second bindings))
Expand Down
10 changes: 5 additions & 5 deletions src/promesa/impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
(.completeExceptionally ^CompletableFuture p v)
p)))

#?(:cljs
(defn coerce
"Coerce a thenable to built-in promise impl type."
[v]
(impl/coerce v)))
(defn coerce
[v]
(if (promise? v)
v
(resolved v)))

(defn all
[promises]
Expand Down

0 comments on commit be4ea19

Please sign in to comment.