Skip to content

Commit ae9da51

Browse files
committed
Moved fn->JavaInterface functions to utils
1 parent a0841a0 commit ae9da51

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

src/manifold/utils.clj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,22 @@
133133
(defmacro definterface+ [name & body]
134134
(when-not (resolve name)
135135
`(definterface ~name ~@body)))
136+
137+
;;;
138+
139+
(defn fn->Function [function]
140+
(reify java.util.function.Function
141+
(apply [_ x] (function x))))
142+
143+
(defn fn->Consumer [function]
144+
(reify java.util.function.Consumer
145+
(accept [_ x] (function x))))
146+
147+
148+
(defn fn->BiFunction [function]
149+
(reify java.util.function.BiFunction
150+
(apply [_ x y] (function x y))))
151+
152+
(defn fn->BiConsumer [function]
153+
(reify java.util.function.BiConsumer
154+
(accept [_ x y] (function x y))))

test/manifold/deferred_stage_test.clj

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
11
(ns manifold.deferred-stage-test
22
(:require [manifold.deferred :as d]
3+
[manifold.utils :refer
4+
[fn->Function fn->Consumer fn->BiFunction fn->BiConsumer]]
35
[clojure.test :refer [deftest is testing]])
46
(:import [java.util.concurrent
57
CompletionStage
68
CompletableFuture
79
Executors]))
810

9-
(defn fn->Function [function]
10-
(reify java.util.function.Function
11-
(apply [_ x] (function x))))
12-
13-
(defn fn->Consumer [function]
14-
(reify java.util.function.Consumer
15-
(accept [_ x] (function x))))
16-
17-
(defn fn->Runnable [function]
11+
(defn fn1->Runnable [function]
1812
(reify java.lang.Runnable
1913
(run [_] (function nil))))
2014

21-
(defn fn->BiFunction [function]
22-
(reify java.util.function.BiFunction
23-
(apply [_ x y] (function x y))))
24-
25-
(defn fn->BiConsumer [function]
26-
(reify java.util.function.BiConsumer
27-
(accept [_ x y] (function x y))))
28-
29-
(defn fn->Runnable' [function]
15+
(defn fn2->Runnable [function]
3016
(reify java.lang.Runnable
3117
(run [_] (function nil nil))))
3218

@@ -71,7 +57,7 @@
7157
:with-executor
7258
(fn [^CompletionStage this operator executor]
7359
(.thenRunAsync this operator executor))}
74-
:interface fn->Runnable
60+
:interface fn1->Runnable
7561
:inner-assertion #(is (= % nil))
7662
:post-assertion #(is (= % nil))}])
7763

@@ -162,7 +148,7 @@
162148
:with-executor
163149
(fn [^CompletionStage this other operator executor]
164150
(.runAfterBothAsync this other operator executor))}
165-
:interface fn->Runnable'
151+
:interface fn2->Runnable
166152
:inner-assertion (fn [_ _])
167153
:post-assertion (fn [_])}])
168154

@@ -262,7 +248,7 @@
262248
:with-executor
263249
(fn [^CompletionStage this other operator executor]
264250
(.runAfterEitherAsync this other operator executor))}
265-
:interface fn->Runnable
251+
:interface fn1->Runnable
266252
:inner-assertion (fn [_])
267253
:post-assertion (fn [_])}])
268254

0 commit comments

Comments
 (0)