-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy patheq.pony
35 lines (35 loc) · 955 Bytes
/
eq.pony
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
primitive JEq
"""
Implements structural JSON equality
"""
fun apply(a: (J | NotSet), b: (J | NotSet)): Bool =>
match (a, b)
| (let a': JObj, let b': JObj) =>
if a'.data.size() != b'.data.size() then return false end
for (k, v) in a'.data.pairs() do
try
if JEq(b'.data(k)?, v) == false then return false end
else return false
end
end
true
| (let a': JArr, let b': JArr) =>
if a'.data.size() != b'.data.size() then return false end
var i: USize = 0
while i < a'.data.size() do
try
if JEq(a'.data(i)?, b'.data(i)?) == false then
return false
end
else return false end
i = i + 1
end
true
| (let a': I64, let b': I64) => a' == b'
| (let a': F64, let b': F64) => a' == b'
| (let a': String, let b': String) => a' == b'
| (let a': Bool, let b': Bool) => a' == b'
| (None, None) => true
| (NotSet, NotSet) => true
else false
end