-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
68 lines (41 loc) · 785 Bytes
/
core.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
(ns mask.core
(:import
java.io.Writer))
(defprotocol IMask
(mask [this])
(unmask [this]))
(deftype Mask [value]
Object
(equals [_ _]
false)
(toString [_this]
"<< masked >>")
IMask
(mask [this]
this)
(unmask [_this]
value))
(defn mask? [object]
(instance? Mask object))
(extend-protocol IMask
nil
(mask [_]
(throw
(new IllegalArgumentException
"Cannot mask a nil value")))
(unmask [this]
this)
Object
(mask [this]
(new Mask this))
(unmask [this]
this))
(defmethod print-method Mask
[masked ^Writer writer]
(.write writer (str masked)))
(defn reader-tag-mask [form]
`(mask ~form))
(defn reader-tag-unmask [form]
`(unmask ~form))
(defn reader-edn [value]
(mask value))