summary refs log tree commit diff
path: root/lib/equal.fnl
diff options
context:
space:
mode:
authordozens2024-05-29 19:26:41 -0600
committerdozens2024-06-02 21:44:17 -0600
commit7c07d6e6ececbf73e18a639e00b3690d4827e12a (patch)
tree7d948da1b634d100feb32215dd5d263c5b01ab8b /lib/equal.fnl
parentf265d24c0cacb92c7f7db19f364a155d87938184 (diff)
tests
Diffstat (limited to 'lib/equal.fnl')
-rw-r--r--lib/equal.fnl22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/equal.fnl b/lib/equal.fnl
new file mode 100644
index 0000000..cc34ada
--- /dev/null
+++ b/lib/equal.fnl
@@ -0,0 +1,22 @@
+;; thanks:
+;; https://gist.github.com/sapphyrus/fd9aeb871e3ce966cc4b0b969f62f539
+;; and antifennel
+(fn deep-equals [o1 o2 ignore-mt]
+  (when (= o1 o2) (lua "return true"))
+  (local o1-type (type o1))
+  (local o2-type (type o2))
+  (when (not= o1-type o2-type) (lua "return false"))
+  (when (not= o1-type :table) (lua "return false"))
+  (when (not ignore-mt)
+    (local mt1 (getmetatable o1))
+    (when (and mt1 mt1.__eq)
+      (let [___antifnl_rtn_1___ (= o1 o2)] (lua "return ___antifnl_rtn_1___"))))
+  (each [key1 value1 (pairs o1)]
+    (local value2 (. o2 key1))
+    (when (or (= value2 nil) (= (deep-equals value1 value2 ignore-mt) false))
+      (lua "return false")))
+  (each [key2 _ (pairs o2)]
+    (when (= (. o1 key2) nil) (lua "return false")))
+  true)	
+
+{:equal deep-equals}