summaryrefslogtreecommitdiff
path: root/src/jester/comparisons.clj
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@zancanaro.id.au>2021-02-23 13:33:02 +1100
committerCarlo Zancanaro <carlo@zancanaro.id.au>2021-02-23 23:24:38 +1100
commit11919c0ebde7c071c5d126cef3d04775d8b450fe (patch)
tree2da90e651130a5cefa060472e30655b2a2a8634f /src/jester/comparisons.clj
Initial commit
Diffstat (limited to 'src/jester/comparisons.clj')
-rw-r--r--src/jester/comparisons.clj36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/jester/comparisons.clj b/src/jester/comparisons.clj
new file mode 100644
index 0000000..c47469e
--- /dev/null
+++ b/src/jester/comparisons.clj
@@ -0,0 +1,36 @@
+(ns jester.comparisons
+ "Comparison functions to specify how Jester comparisons work.")
+
+(defn string=
+ "Compare two (potentially-nil) strings. If either is nil, return nil.
+ Otherwise, return true iff a = b, ignoring case, and false
+ otherwise."
+ [^String a, ^String b]
+ (boolean (and a b (.equalsIgnoreCase a b))))
+
+(defn string<
+ "Compare two (potentially-nil) strings. If either is nil, return nil.
+ Otherwise, return true iff a < b, ignoring case, and false
+ otherwise."
+ [^String a, ^String b]
+ (and a b (< (.compareToIgnoreCase a b) 0)))
+
+(defn number=
+ "Compare two (potentially-nil) numbers. If either is nil, return nil.
+ If either is NaN, return false. Otherwise, return true iff a = b,
+ and false otherwise."
+ [a b]
+ (boolean (and a b (== a b))))
+
+(defn number<
+ "Compare two (potentially-nil) numbers. If either is nil, return nil.
+ If either is NaN, return false. Otherwise, return true iff a < b,
+ and false otherwise."
+ [a b]
+ (boolean (and a b (< a b))))
+
+(defn boolean=
+ "Compare two (potentially-nil) booleans. If either is nil, return nil.
+ Otherwise, return true iff a = b, and false otherwise."
+ [a b]
+ (boolean (and (some? a) (some? b) (= a b))))