Skip to content

Commit

Permalink
Merge pull request #8 from athos/feature/ctor-call-support
Browse files Browse the repository at this point in the history
Support for ctor calls in thread macros
  • Loading branch information
athos authored Nov 8, 2019
2 parents ba8003a + 60f785d commit 1f28eab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/kitchen_async/promise.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@
(kitchen-async.promise/recur ~cond)))))

(defn- interop? [form]
(and (symbol? form) (= (nth (name form) 0) \.)))
(and (symbol? form)
(cc/let [n (name form)]
(or (= (first n) \.) ; member access
(= (last n) \.))))) ; ctor call

(defmacro -> [x & forms]
(if forms
Expand Down
30 changes: 30 additions & 0 deletions test/common/kitchen_async/promise_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@
(is (= 2 @i))
(done))))))

(defrecord R [x])

(deftest ->-test
(async done
(p/then (p/-> (p/timeout 0 39)
Expand All @@ -192,6 +194,13 @@
(is (= 42 x))
(done)))))

(deftest ->-with-ctor-call-test
(async done
(p/then (p/-> (p/timeout 0 42) R.)
(fn [r]
(is (= r (->R 42)))
(done)))))

(deftest ->>-test
(async done
(p/then (p/->> (p/resolve 41)
Expand All @@ -210,6 +219,13 @@
(is (= 42 x))
(done)))))

(deftest ->>-with-ctor-call-test
(async done
(p/then (p/->> (p/timeout 0 42) R.)
(fn [r]
(is (= r (->R 42)))
(done)))))

(deftest some->-non-nil-test
(async done
(p/then (p/some-> (p/resolve 43)
Expand Down Expand Up @@ -238,6 +254,13 @@
(is (= 42 x))
(done)))))

(deftest some->-with-ctor-call-test
(async done
(p/then (p/some-> (p/resolve 42) R.)
(fn [r]
(is (= r (->R 42)))
(done)))))

(deftest some->>-non-nil-test
(async done
(p/then (p/some->> (p/resolve 1)
Expand Down Expand Up @@ -266,6 +289,13 @@
(is (= 42 x))
(done)))))

(deftest some->>-with-ctor-call-test
(async done
(p/then (p/some->> (p/resolve 42) R.)
(fn [r]
(is (= r (->R 42)))
(done)))))

(deftest try-success-test
(async done
(p/then (p/try 42)
Expand Down

0 comments on commit 1f28eab

Please sign in to comment.