Skip to content

Instantly share code, notes, and snippets.

@aryszka
Last active July 3, 2020 11:57
Show Gist options
  • Save aryszka/7afca98f52477671918faf50ee78c50b to your computer and use it in GitHub Desktop.
Save aryszka/7afca98f52477671918faf50ee78c50b to your computer and use it in GitHub Desktop.
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:]...)
}
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