/
fn.clj
95 lines (79 loc) · 1.66 KB
/
fn.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
(ns qbits.fn
(:import (java.util.function Function
BiFunction
BiConsumer
Supplier
Consumer
Predicate
LongConsumer
DoubleConsumer)))
(defn supplier*
^Supplier
[f]
(reify Supplier
(get [_] (f))))
(defmacro supplier
{:style/indent 1}
[& args]
`(supplier* (fn ~@args)))
(defn function*
^Function
[f]
(reify Function
(apply [_ x] (f x))))
(defmacro function
{:style/indent 1}
[& args]
`(function* (fn ~@args)))
(defn bifunction*
^BiFunction
[f]
(reify BiFunction
(apply [_ x y]
(f x y))))
(defmacro bifunction
{:style/indent 1}
[& args]
`(bifunction* (fn ~@args)))
(defn consumer*
^Consumer
[f]
(reify Consumer
(accept [_ x] (f x))))
(defmacro consumer
{:style/indent 1}
[& args]
`(consumer* (fn ~@args)))
(defn biconsumer*
^BiConsumer
[f]
(reify BiConsumer
(accept [_ x y]
(f x y))))
(defmacro biconsumer
{:style/indent 1}
[& args] `(biconsumer* (fn ~@args)))
(defn long-consumer*
^LongConsumer
[f]
(reify LongConsumer
(accept [_ x] (f x))))
(defmacro long-consumer
{:style/indent 1}
[& args] `(long-consumer* (fn ~@args)))
(defn double-consumer*
^DoubleConsumer
[f]
(reify DoubleConsumer
(accept [_ x] (f x))))
(defmacro double-consumer
{:style/indent 1}
[& args] `(double-consumer* (fn ~@args)))
(defn runnable*
^Runnable
[f]
(reify Runnable
(run [_] (f))))
(defmacro runnable
{:style/indent 1}
[& args] `(runnable* (fn ~@args)))