Skip to content

Commit

Permalink
Remove nothing from JsonLike
Browse files Browse the repository at this point in the history
  • Loading branch information
bmjames committed Nov 15, 2013
1 parent 0debf48 commit 7525e05
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 10 deletions.
4 changes: 0 additions & 4 deletions core/src/main/scala/com/gu/json/Cursor.scala
Expand Up @@ -30,10 +30,6 @@ case class Cursor[J](focus: J, path: Path[J])(implicit J: JsonLike[J]) {
def withFocusF[F[_] : Functor](f: J => F[J]): F[Cursor[J]] =
Functor[F].map(f(focus))(replace)

/** Replace the value at the focus with JNothing */
def setNothing: Cursor[J] =
replace(J.nothing)

/** Delete the value at the focus, and move up one level */
def deleteGoUp: Option[Cursor[J]] =
condOpt(path) {
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala/com/gu/json/CursorArrow.scala
Expand Up @@ -71,8 +71,6 @@ object CursorArrows {

def deleteGoUp[J]: CursorArrow[J] = withFailure(_.deleteGoUp, "deleteGoUp")

def setNothing[J](implicit J: JsonLike[J]): CursorArrow[J] = replace(J.nothing)

def eachElem[J](that: CursorArrow[J])(implicit J: JsonLike[J]) = CursorArrow[J] { case cursor @ Cursor(focus, p) =>
J.asArray(focus) match {
case Some(elems) =>
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala/com/gu/json/JsonLike.scala
Expand Up @@ -3,7 +3,6 @@ package com.gu.json
/** Typeclass for a data structure representing an AST for JSON */
trait JsonLike[J] {

def nothing: J
def array(elems: Seq[J]): J
def obj(fields: Seq[(String, J)]): J
def string(s: String): J
Expand All @@ -25,7 +24,6 @@ object JsonLike {
}

object Json {
def nothing[J : JsonLike]: J = JsonLike[J].nothing
def array[J : JsonLike](elems: Seq[J]): J = JsonLike[J].array(elems)
def obj[J : JsonLike](fields: Seq[(String, J)]): J = JsonLike[J].obj(fields)
def string[J : JsonLike](s: String): J = JsonLike[J].string(s)
Expand Down
Expand Up @@ -7,7 +7,6 @@ import com.gu.json.JsonLike
trait JsonLikeInstances {

implicit val json4sJsonLike: JsonLike[JValue] = new JsonLike[JValue] {
val nothing = JNothing
def array(elems: Seq[JValue]) = JArray(elems.toList)
def obj(fields: Seq[(String, JValue)]) = JObject(fields.toList)
def string(s: String) = JString(s)
Expand Down
2 changes: 1 addition & 1 deletion test/src/test/scala/com.gu.json/CursorArrowExamples.scala
Expand Up @@ -77,7 +77,7 @@ class CursorArrowExamples extends FunSuite with ShouldMatchers {
test("Guard an action using *>") {

// Delete any element in "assets" that has a field named "caption"
val updated = json run field("assets") >=> eachElem(try_(field("caption") *> setNothing))
val updated = json run field("assets") >=> eachElem(try_(field("caption") *> replace(JNothing)))

updated.map(_.noNulls) should be (\/-(parse(
"""
Expand Down

0 comments on commit 7525e05

Please sign in to comment.