Zipper

zipper.Zipper
See theZipper companion object
case class Zipper[A](left: List[A], focus: A, right: List[A], top: Option[Zipper[A]])(implicit unzip: Unzip[A])

A Zipper allows to move around a recursive immutable data structure and perform updates.

Example:

 case class Tree(x: Int, c: List[Tree] = List.empty)

 val before = Tree(1, List(Tree(2)))
 val after = Tree(1, List(Tree(2), Tree(3)))

 Zipper(before).moveDownRight.insertRight(Tree(3, Nil)).commit shouldEqual after

See https://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/huet-zipper.pdf.

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

Move to the next position in depth-first left-to-right order, or throw if impossible

Move to the next position in depth-first left-to-right order, or throw if impossible

Attributes

Move to the next position in depth-first right-to-left order, or throw if impossible

Move to the next position in depth-first right-to-left order, or throw if impossible

Attributes

def commit: A

Zip to the top and return the resulting value

Zip to the top and return the resulting value

Attributes

def cycle(move0: () => A, moves: () => A*): Zipper[A]

Cycle through the moves until a failure is produced and return the last success

Cycle through the moves until a failure is produced and return the last success

Attributes

Delete the value in focus and move to the next position in depth-first right-to-left order, or throw if impossible

Delete the value in focus and move to the next position in depth-first right-to-left order, or throw if impossible

Attributes

Delete the value in focus and move to the next position in depth-first left-to-right order, or throw if impossible

Delete the value in focus and move to the next position in depth-first left-to-right order, or throw if impossible

Attributes

Delete the value in focus and move left, or throw if impossible

Delete the value in focus and move left, or throw if impossible

Attributes

Delete the value in focus and move right, or throw if impossible

Delete the value in focus and move right, or throw if impossible

Attributes

Delete the value in focus and move up, or throw if impossible

Delete the value in focus and move up, or throw if impossible

Attributes

def fail: MoveResult[A]
def insertDownLeft(values: List[A]): Zipper[A]

Move down left and insert a list of values on the left, focusing on the first one

Move down left and insert a list of values on the left, focusing on the first one

Attributes

def insertDownRight(values: List[A]): Zipper[A]

Move down right and insert a list of values on the right, focusing on the last one

Move down right and insert a list of values on the right, focusing on the last one

Attributes

def insertLeft(value: A): Zipper[A]

Insert a new value to the left of focus

Insert a new value to the left of focus

Attributes

def insertRight(value: A): Zipper[A]

Insert a new value to the right of focus

Insert a new value to the right of focus

Attributes

final def loopAccum[B](acc: B)(f: (Zipper[A], B) => (MoveResult[A], B)): (Zipper[A], B)

Loop and accumulate state until a failure is produced

Loop and accumulate state until a failure is produced

Attributes

def moveDownAt(index: Int): Zipper[A]

Unzip the current node and focus on the nth child, or throw if impossible

Unzip the current node and focus on the nth child, or throw if impossible

Attributes

Unzip the current node and focus on the left child, or throw if impossible

Unzip the current node and focus on the left child, or throw if impossible

Attributes

Unzip the current node and focus on the right child, or throw if impossible

Unzip the current node and focus on the right child, or throw if impossible

Attributes

def moveLeft: Zipper[A]

Move left or throw if impossible

Move left or throw if impossible

Attributes

def moveLeftBy(n: Int): Zipper[A]

Move left by n or throw if impossible

Move left by n or throw if impossible

Attributes

def moveRight: Zipper[A]

Move right or throw if impossible

Move right or throw if impossible

Attributes

def moveRightBy(n: Int): Zipper[A]

Move right by n or throw if impossible

Move right by n or throw if impossible

Attributes

def moveTo(z: Zipper[A]): MoveResult[A]
def moveUp: Zipper[A]

Zip the current layer and move up, or throw if impossible

Zip the current layer and move up, or throw if impossible

Attributes

def repeat(n: Int, move: () => A): Zipper[A]

Repeat a move n times or throw if impossible

Repeat a move n times or throw if impossible

Attributes

def repeatWhile(condition: A => Boolean, move: () => A): Zipper[A]

Repeat a move while the condition is satisfied or throw if impossible

Repeat a move while the condition is satisfied or throw if impossible

Attributes

Returns

the first zipper that does not satisfy the condition

def repeatWhileNot(condition: A => Boolean, move: () => A): Zipper[A]

Repeat a move while the condition is not satisfied or throw if impossible

Repeat a move while the condition is not satisfied or throw if impossible

Attributes

Returns

the first zipper that satisfies the condition

def rewindLeft: Zipper[A]

Move to the leftmost position

Move to the leftmost position

Attributes

Move to the rightmost position

Move to the rightmost position

Attributes

def set(value: A): Zipper[A]

Replace the focus with a different value

Replace the focus with a different value

Attributes

def stay: MoveResult[A]
def tapFocus(f: A => Unit): Zipper[A]

Perform a side-effect on the focus

Perform a side-effect on the focus

Attributes

Move to the next position in depth-first left-to-right order

Move to the next position in depth-first left-to-right order

Attributes

Move to the next position in depth-first right-to-left order

Move to the next position in depth-first right-to-left order

Attributes

Delete the value in focus and move to the next position in depth-first right-to-left order

Delete the value in focus and move to the next position in depth-first right-to-left order

Attributes

Delete the value in focus and move to the next position in depth-first left-to-right order

Delete the value in focus and move to the next position in depth-first left-to-right order

Attributes

Delete the value in focus and move left

Delete the value in focus and move left

Attributes

Delete the value in focus and move right

Delete the value in focus and move right

Attributes

Delete the value in focus and move up

Delete the value in focus and move up

Attributes

def tryInsertDownLeft(values: List[A]): MoveResult[A]

Move down left and insert a list of values on the left, focusing on the first one

Move down left and insert a list of values on the left, focusing on the first one

Attributes

def tryInsertDownRight(values: List[A]): MoveResult[A]

Move down right and insert a list of values on the right, focusing on the last one

Move down right and insert a list of values on the right, focusing on the last one

Attributes

def tryMoveDownAt(index: Int): MoveResult[A]

Unzip the current node and focus on the nth child

Unzip the current node and focus on the nth child

Attributes

Unzip the current node and focus on the left child

Unzip the current node and focus on the left child

Attributes

Unzip the current node and focus on the right child

Unzip the current node and focus on the right child

Attributes

Move left

Move left

Attributes

def tryMoveLeftBy(n: Int): MoveResult[A]

Move left by n

Move left by n

Attributes

Move right

Move right

Attributes

def tryMoveRightBy(n: Int): MoveResult[A]

Move right by n

Move right by n

Attributes

Zip the current layer and move up

Zip the current layer and move up

Attributes

def tryRepeat(n: Int, move: () => A): MoveResult[A]

Repeat a move n times

Repeat a move n times

Attributes

def tryRepeatWhile(condition: A => Boolean, move: () => A): MoveResult[A]

Repeat a move while the condition is satisfied

Repeat a move while the condition is satisfied

Attributes

Returns

the first zipper that does not satisfy the condition, or failure

def tryRepeatWhileNot(condition: A => Boolean, move: () => A): MoveResult[A]

Repeat a move while the condition is not satisfied

Repeat a move while the condition is not satisfied

Attributes

Returns

the first zipper that satisfies the condition, or failure

def update(f: A => A): Zipper[A]

Update the focus by applying a function

Update the focus by applying a function

Attributes

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product

Implicits

Implicits

implicit val unzip: Unzip[A]