Last active
July 3, 2020 11:57
-
-
Save aryszka/7afca98f52477671918faf50ee78c50b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "lists" | |
// with checking circular references: | |
fn deepEq(...a) { | |
fn deepEq2Lists(refs, a, b) | |
len(a) == len(b) && | |
lists.every(fn(i) deepEq2(refs, a[i], b[i]), lists.indexes(a)) | |
fn deepEq2Structs(refs, a, b) | |
len(keys(a)) == len(keys(b)) && | |
lists.every(fn(key) deepEq2(refs, a[key], b[key]), keys(a)) | |
fn deepEq2(refs, a, b) | |
!lists.contains(a, refs) && ( | |
is([], a) && is([], b) && deepEq2Lists([refs..., a], a, b) || | |
is({}, a) && is({}, b) && deepEq2Structs([refs..., a], a, b) || | |
a == b | |
) | |
return len(a) < 2 || deepEq2([], a[0], a[1]) && deepEq(a[1:]...) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "lists" | |
// without checking circular references: | |
fn deepEq(...a) { | |
fn deepEq2Lists(a, b) | |
len(a) == len(b) && | |
lists.every(fn(i) deepEq2(a[i], b[i]), lists.indexes(a)) | |
fn deepEq2Structs(a, b) | |
len(keys(a)) == len(keys(b)) && | |
lists.every(fn(key) deepEq2(a[key], b[key]), keys(a)) | |
fn deepEq2(a, b) | |
is([], a) && is([], b) && deepEq2Lists(a, b) || | |
is({}, a) && is({}, b) && deepEq2Structs(a, b) || | |
a == b | |
return len(a) < 2 || deepEq2(a[0], a[1]) && deepEq(a[1:]...) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment