Skip to content

Commit

Permalink
Scala: fix nested sequence/hash-map equality.
Browse files Browse the repository at this point in the history
Related to kanaka#123
  • Loading branch information
kanaka committed Dec 2, 2015
1 parent 66fb556 commit 30047c0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions scala/types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,20 @@ object types {

def _equal_Q(a: Any, b: Any): Any = {
(a, b) match {
case (a: MalList, b: MalList) => a.value == b.value
case (a: MalHashMap, b: MalHashMap) => a.value == b.value
case (a: MalList, b: MalList) => {
if (a.value.length != b.value.length) return false
for ( (x, y) <- (a.value zip b.value) ) {
if (_equal_Q(x, y) != true) return false
}
true
}
case (a: MalHashMap, b: MalHashMap) => {
if (a.value.size != b.value.size) return false
for ( (k,v) <- a.value ) {
if (_equal_Q(v,b.value(k)) != true) return false
}
true
}
case _ => a == b
}
}
Expand Down

0 comments on commit 30047c0

Please sign in to comment.