feat: Add vector deepEqual
This commit is contained in:
parent
3b882f3d53
commit
7b799f7183
6 changed files with 41 additions and 1 deletions
20
src/vector/relational.js
Normal file
20
src/vector/relational.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
import {Vector} from './Vector.js'
|
||||
import {NotAType, Returns} from '#core/Type.js'
|
||||
import {Any, match} from '#core/TypePatterns.js'
|
||||
import {BooleanT} from '#boolean/BooleanT.js'
|
||||
|
||||
export const deepEqual = [
|
||||
match([Vector, Any], Returns(BooleanT, () => false)),
|
||||
match([Any, Vector], Returns(BooleanT, () => false)),
|
||||
match([Vector, Vector], (math, [V, W]) => {
|
||||
if (V.Component === NotAType || W.Component === NotAType) {
|
||||
return Returns(BooleanT, (v, w) => v === w
|
||||
|| (v.length === w.length
|
||||
&& v.every((e, i) => math.deepEqual(e, w[i]))))
|
||||
}
|
||||
const compDeep = math.deepEqual.resolve([V.Component, W.Component])
|
||||
return Returns(BooleanT, (v,w) => v === w
|
||||
|| (v.length === w.length
|
||||
&& v.every((e, i) => compDeep(e, w[i]))))
|
||||
})
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue