summaryrefslogtreecommitdiff
path: root/src/jester/comparisons.clj
blob: c47469e14b93d4cde7d4e4b479f5c856259ad259 (about) (plain)
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
(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))))