Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors in HCursor #188

Merged
merged 1 commit into from
Aug 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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