Skip to content

Commit

Permalink
Merge pull request #188 from travisbrown/fix-hcursor
Browse files Browse the repository at this point in the history
Fix errors in HCursor.
  • Loading branch information
seanparsons committed Aug 11, 2015
2 parents acafd23 + bedc693 commit c2bf2bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/main/scala/argonaut/CursorOpElement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ case object CursorOpDeleteGoLast extends CursorOpElement
case class CursorOpDeleteGoField(f: JsonField) extends CursorOpElement
case object CursorOpDeleteLefts extends CursorOpElement
case object CursorOpDeleteRights extends CursorOpElement
case class CursorOpSetLefts(x: List[Json]) extends CursorOpElement
case class CursorOpSetRights(x: List[Json]) extends CursorOpElement

object CursorOpElement extends CursorOpElements

Expand Down Expand Up @@ -95,6 +97,8 @@ trait CursorOpElements {
case CursorOpDeleteGoField(f) => "!--(" + f + ")"
case CursorOpDeleteLefts => "!<"
case CursorOpDeleteRights => ">!"
case CursorOpSetLefts(_) => "!...<"
case CursorOpSetRights(_) => ">...!"
}

def equal(e1: CursorOpElement, e2: CursorOpElement) =
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/argonaut/HCursor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ case class HCursor(cursor: Cursor, history: CursorHistory) {

/** Move the cursor to the first in a JSON array. */
def first: ACursor =
history.acursorElement(Store(_.left, cursor), CursorOpFirst)
history.acursorElement(Store(_.first, cursor), CursorOpFirst)

/** Move the cursor to the last in a JSON array. */
def last: ACursor =
history.acursorElement(Store(_.left, cursor), CursorOpLast)
history.acursorElement(Store(_.last, cursor), CursorOpLast)

/** Move the cursor left in a JSON array the given number of times. A negative value will move the cursor right (alias for `leftN`). */
def -<-:(n: Int): ACursor =
Expand Down Expand Up @@ -132,7 +132,7 @@ case class HCursor(cursor: Cursor, history: CursorHistory) {

/** Find the first element at or to the right of focus in a JSON array where the given predicate matches the focus. */
def find(p: Json => Boolean): ACursor =
history.acursorElement(Store(_.find(p), cursor), CursorOpRightAt(p))
history.acursorElement(Store(_.find(p), cursor), CursorOpFind(p))

/** Move the cursor to the given sibling field in a JSON object (alias for `field`). */
def --(q: JsonField): ACursor =
Expand Down Expand Up @@ -216,11 +216,11 @@ case class HCursor(cursor: Cursor, history: CursorHistory) {

/** Set the values to the left of focus in a JSON array. */
def setLefts(x: List[Json]): ACursor =
history.acursorElement(Store(_.setLefts(x), cursor), CursorOpDeleteRights)
history.acursorElement(Store(_.setLefts(x), cursor), CursorOpSetLefts(x))

/** Set the values to the right of focus in a JSON array. */
def setRights(x: List[Json]): ACursor =
history.acursorElement(Store(_.setRights(x), cursor), CursorOpDeleteRights)
history.acursorElement(Store(_.setRights(x), cursor), CursorOpSetRights(x))

/** Move the cursor up one step to the parent context. */
def up: ACursor =
Expand Down

0 comments on commit c2bf2bb

Please sign in to comment.