Skip to content

Instantly share code, notes, and snippets.

@stanch
Created April 17, 2017 22:15
Show Gist options
  • Save stanch/bb71ce3cefe8347e1bdfded8ba802c44 to your computer and use it in GitHub Desktop.
Save stanch/bb71ce3cefe8347e1bdfded8ba802c44 to your computer and use it in GitHub Desktop.
def tapRender[B: ToRefTree](value: B) = { render(value); value }
def zipperControl[A](zipper: Zipper[A])(implicit toRefTree: ToRefTree[Zipper[A]]): Unit = {
Iterator
.continually(Console.in.read())
.takeWhile(_ != 'q')
.filter(Set('w', 'a', 's', 'd'))
.foldLeft(tapRender(zipper)) {
case (z, 'w') ⇒ tapRender(z.tryMoveUp.orStay)
case (z, 'a') ⇒ tapRender(z.tryMoveLeft.orStay)
case (z, 's') ⇒ tapRender(z.tryMoveDownLeft.orStay)
case (z, 'd') ⇒ tapRender(z.tryMoveRight.orStay)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment