Skip to content

Instantly share code, notes, and snippets.

@aoiroaoino
Created September 28, 2014 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aoiroaoino/efb3398bd868f40d7a78 to your computer and use it in GitHub Desktop.
Save aoiroaoino/efb3398bd868f40d7a78 to your computer and use it in GitHub Desktop.
import scalaz._, Scalaz._
type Field = Vector[Vector[Option[String]]]
object Field {
def update(x: Int, y: Int): PLens[Field, Option[String]] = {
PLens.vectorNthPLens(y) >=> PLens.vectorNthPLens(x)
}
}
def updateDot(x: Int, y: Int, s: String)(field: Field) = {
Field.update(x,y).set(field, Some(s))
}
val f = Vector.fill(3)(Vector.fill(3)(Option.empty[String]))
updateDot(0,0,"aaa")(f)
// => res13: Option[Field] = Some(Vector(Vector(Some(aaa), None, None), Vector(None, None, None), Vector(None, None, None)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment