-
Notifications
You must be signed in to change notification settings - Fork 5
/
inter_ops.clj
193 lines (168 loc) · 7.44 KB
/
inter_ops.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
(ns io.randomseed.bankster.money.inter-ops
^{:doc "Bankster library, transparent wrappers for money operations."
:author "Paweł Wilk"
:added "1.0.0"}
(:refer-clojure :exclude [> < >= <= + - * / = not= long int double float compare pos? neg?])
(:require [io.randomseed.bankster :refer :all]
[io.randomseed.bankster.scale :as scale]
[io.randomseed.bankster.currency :as currency]
[io.randomseed.bankster.money :as money]
[io.randomseed.bankster.money :refer [money?]]
[io.randomseed.bankster.util :refer :all])
(:import [io.randomseed.bankster Currency Registry Money]
[java.math MathContext RoundingMode]))
(defn +
"Calls io.randomseed.bankster.money/add for Money argument, clojure.core/+ for other
data types."
{:added "1.0.0"}
([] (money/add))
([a] a)
([a b] (if (money? a) (money/add a b) (clojure.core/+ a b)))
([a b & more] (if (money? a) (apply money/add a b more) (apply clojure.core/+ a b more))))
(defn -
"Calls io.randomseed.bankster.money/sub for Money argument, clojure.core/- for other
data types."
{:added "1.0.0"}
([a] (if (money? a) (money/sub a) (clojure.core/- a)))
([a b] (if (money? a) (money/sub a b) (clojure.core/- a b)))
([a b & more] (if (money? a) (apply money/sub a b more) (apply clojure.core/- a b more))))
(defn *
"Calls io.randomseed.bankster.money/mul for Money argument, clojure.core/* for other
data types."
{:added "1.0.0"}
([] (money/mul))
([a] (if (money? a) (money/mul a) (num a)))
([a b] (if (or (money? a) (money? b)) (money/mul a b) (clojure.core/* a b)))
([a b & more] (apply money/mul a b more)))
(defn /
"Calls io.randomseed.bankster.money/div for Money argument, clojure.core// for other
data types."
{:added "1.0.0"}
([a] (if (money? a) (money/div a) (clojure.core// a)))
([a b] (if (money? a) (money/div a b) (clojure.core// a b)))
([a b & more] (if (money? a) (apply money/div a b more) (apply clojure.core// a b more))))
(defn =
"Calls io.randomseed.bankster.money/eq? for Money argument, clojure.core/= for other
data types."
{:tag Boolean :added "1.0.0"}
([a] true)
([a b] (if (money? a) (if (money? b) (money/eq? a b) false) (if (money? b) false (clojure.core/= a b))))
([a b & more] (if (= a b)
(if (next more)
(recur b (first more) (next more))
(= b (first more)))
false)))
(defn not=
"Calls io.randomseed.bankster.money/ne? for Money argument, clojure.core/not= for
other data types."
{:tag Boolean :added "1.0.0"}
([a] false)
([a b] (if (money? a) (if (money? b) (money/ne? a b) true) (if (money? b) true (clojure.core/not= a b))))
([a b & more] (if (not= a b)
(if (next more)
(recur b (first more) (next more))
(not= b (first more)))
true)))
(defn >
"Calls io.randomseed.bankster.money/gt? for Money argument, clojure.core/> for other
data types."
{:tag Boolean :added "1.0.0"}
(^Boolean [a] true)
(^Boolean [a b] (if (money? a) (if (money? b) (money/gt? a b) false) (if (money? b) false (clojure.core/> a b))))
(^Boolean [a b & more] (if (> a b)
(if (next more)
(recur b (first more) (next more))
(> b (first more)))
false)))
(defn >=
"Calls io.randomseed.bankster.money/ge? for Money argument, clojure.core/>= for other
data types."
{:tag Boolean :added "1.0.0"}
(^Boolean [a] true)
(^Boolean [a b] (if (money? a) (if (money? b) (money/ge? a b) false) (if (money? b) false (clojure.core/>= a b))))
(^Boolean [a b & more] (if (>= a b)
(if (next more)
(recur b (first more) (next more))
(>= b (first more)))
false)))
(defn <
"Calls io.randomseed.bankster.money/lt? for Money argument, clojure.core/> for other
data types."
{:tag Boolean :added "1.0.0"}
(^Boolean [a] true)
(^Boolean [a b] (if (money? a) (if (money? b) (money/lt? a b) false) (if (money? b) false (clojure.core/< a b))))
(^Boolean [a b & more] (if (< a b)
(if (next more)
(recur b (first more) (next more))
(< b (first more)))
false)))
(defn <=
"Calls io.randomseed.bankster.money/le? for Money argument, clojure.core/<= for other
data types."
{:tag Boolean :added "1.0.0"}
(^Boolean [a] true)
(^Boolean [a b] (if (money? a) (if (money? b) (money/le? a b) false) (if (money? b) false (clojure.core/<= a b))))
(^Boolean [a b & more] (if (<= a b)
(if (next more)
(recur b (first more) (next more))
(<= b (first more)))
false)))
(defn long
"Calls io.randomseed.bankster.money/major->long for Money argument, clojure.core/long
for other data types."
{:tag 'long :added "1.0.0"}
[a] (if (money? a) (money/major->long a) (clojure.core/long a)))
(defn int
"Calls io.randomseed.bankster.money/major->int for Money argument, clojure.core/int
for other data types."
{:tag 'int :added "1.0.0"}
[a] (if (money? a) (money/major->int a) (clojure.core/int a)))
(defn double
"Calls io.randomseed.bankster.money/->double for Money argument, clojure.core/double
for other data types."
{:tag 'double :added "1.0.0"}
[a] (if (money? a) (money/->double a) (clojure.core/double a)))
(defn float
"Calls io.randomseed.bankster.money/->float for Money argument, clojure.core/float
for other data types."
{:tag 'float :added "1.0.0"}
[a] (if (money? a) (money/->float a) (clojure.core/float a)))
(defn pos?
"Calls io.randomseed.bankster.money/is-pos? for Money argument, clojure.core/pos?
for other data types."
{:tag Boolean :added "1.0.0"}
[a] (if (money? a) (money/is-pos? a) (clojure.core/pos? a)))
(defn neg?
"Calls io.randomseed.bankster.money/is-neg? for Money argument, clojure.core/neg?
for other data types."
{:tag Boolean :added "1.0.0"}
[a] (if (money? a) (money/is-neg? a) (clojure.core/neg? a)))
(def ^{:tag BigDecimal
:arglists '(^BigDecimal [^Money a]
^BigDecimal [^Money a scale]
^BigDecimal [^Money a scale ^RoundingMode rounding-mode])}
integer
"Alias for io.randomseed.bankster.scale/integer."
scale/integer)
(def ^{:tag BigDecimal
:arglists '(^BigDecimal [^Money a]
^BigDecimal [^Money a scale]
^BigDecimal [^Money a scale ^RoundingMode rounding-mode])}
fractional
"Alias for io.randomseed.bankster.scale/fractional."
scale/fractional)
(def ^{:tag BigDecimal
:arglists '(^BigDecimal [^Money a])}
major
"Alias for io.randomseed.bankster.money/major."
money/major)
(def ^{:tag BigDecimal
:arglists '(^BigDecimal [^Money a])}
minor
"Alias for io.randomseed.bankster.money/minor."
money/minor)
(defn compare
"Calls io.randomseed.bankster.money/compare for Money argument, clojure.core/compare
for other data types."
{:tag 'int :added "1.0.0"}
[a b] (if (money? a) (money/compare a b) (clojure.core/compare a b)))