playframework / playframework/play-json

Monoid[JsObject] does not satisfy associative law

Open
#6 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
375
Forks
140
Avg merge
1d 5h
Merged PRs (30d)
28

Description

(Moved from playframework/playframework#4651)

Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import play.api.libs.json._
import play.api.libs.json._

scala> import play.api.libs.json.Reads.JsObjectMonoid
import play.api.libs.json.Reads.JsObjectMonoid

scala> val a = Json.obj("key" -> Json.obj("x" -> 1))
a: play.api.libs.json.JsObject = {"key":{"x":1}}

scala> val b = Json.obj("key" -> 2)
b: play.api.libs.json.JsObject = {"key":2}

scala> val c = Json.obj("key" -> Json.obj("y" -> 3))
c: play.api.libs.json.JsObject = {"key":{"y":3}}

scala> JsObjectMonoid.append(JsObjectMonoid.append(a, b), c)
res0: play.api.libs.json.JsObject = {"key":{"y":3}}

scala> JsObjectMonoid.append(a, JsObjectMonoid.append(b, c))
res1: play.api.libs.json.JsObject = {"key":{"x":1,"y":3}}
libraryDependencies += "com.typesafe.play" %% "play-json" % "2.4.0"

scalaVersion := "2.11.6"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the documented Scala REPL expressions using Reads.JsObjectMonoid.append with the three JsObject values shown. Inspect the JsObjectMonoid implementation and existing law or JSON-object tests, if present. Done should include behavior that satisfies the associative law for this example and a regression test covering it.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.