Open gmethvin opened 7 years ago
What is the solution to this? You can't have a Monoid
that isn't associative, it makes it unpredictable and dangerous.
The only JsObject
monoid that makes sense is replacing the keys if a duplicate is found on a summand, not deepMerge
.
I would be in favour of either removing the monoid instance entirely or implementing the above, but it is a major behaviour change either way.
I think the current solution of just keeping it is the worst of the three.
A further solution is the same as lift's:
def ++(other: JValue) = {
def append(value1: JValue, value2: JValue): JValue = (value1, value2) match {
case (JNothing, x) => x
case (x, JNothing) => x
case (JArray(xs), JArray(ys)) => JArray(xs ::: ys)
case (JArray(xs), v: JValue) => JArray(xs ::: List(v))
case (v: JValue, JArray(xs)) => JArray(v :: xs)
case (x, y) => JArray(x :: y :: Nil)
}
append(this, other)
}
where everything becomes an array on addition. Which is not obvious behaviour but is at least associative
(Moved from playframework/playframework#4651)