Skip to content

Loading…

Add lenses for Cells #16

Closed
folone opened this Issue · 2 comments

1 participant

@folone
Owner

No description provided.

@folone folone was assigned
@folone folone added a commit that referenced this issue
@folone re #16 Initial implementation. 5d76b07
@folone
Owner

Should add some docs on this. Here's a REPL session to start with:

scala> import info.folone.scala.poi._
import info.folone.scala.poi._

scala> cellLens.get(Cell(1, "data"))
res1: scalaz.Id.Id[String] = data

scala> cellLens.set(Cell(1, "data"), "new data")
res2: scalaz.Id.Id[info.folone.scala.poi.Cell] = Cell(1,new data)

scala> rowLens.contains(Cell(2, "data1"))
res5: scalaz.package.Lens[info.folone.scala.poi.Row,Boolean] = scalaz.LensTFunctions$$anon$5@7d9331eb

scala> res5(Row(1)(Set(Cell(1, "data"), Cell(2, "data1"))))
res7: scalaz.Id.Id[scalaz.package.Store[Boolean,info.folone.scala.poi.Row]] = scalaz.StoreTFunctions$$anon$5@51733a5

scala> rowLens.contains(Cell(2, "data1")).get(Row(1)(Set(Cell(1,"data"), Cell(2, "data1"))))
res8: scalaz.Id.Id[Boolean] = true

scala> rowLens.contains(Cell(2, "data1")).get(Row(1)(Set(Cell(1,"data"), Cell(2, "data"))))
res9: scalaz.Id.Id[Boolean] = false

scala> (rowLens += Cell(2, "data1")).run(Row(1)(Set(Cell(1, "data"), Cell(3, "data3"))))
res14: (info.folone.scala.poi.Row, Set[info.folone.scala.poi.Cell]) = (Row (1)(Set(Cell(1,data), Cell(3,data3), Cell(2,data1))),Set(Cell(1,data), Cell(3,data3), Cell(2,data1)))

scala> (rowLens &= Set(Cell(2, "data1"))).run(Row(1)(Set(Cell(1, "data"), Cell(2, "data1"))))
res17: (info.folone.scala.poi.Row, Set[info.folone.scala.poi.Cell]) = (Row (1)(Set(Cell(2,data1))),Set(Cell(2,data1)))

scala> (rowLens &~= Set(Cell(2, "data1"))).run(Row(1)(Set(Cell(1, "data"), Cell(2, "data1"))))
res18: (info.folone.scala.poi.Row, Set[info.folone.scala.poi.Cell]) = (Row (1)(Set(Cell(1,data))),Set(Cell(1,data)))

scala> (rowLens |= Set(Cell(2, "data1"))).run(Row(1)(Set(Cell(1, "data"), Cell(2, "data1"))))
res20: (info.folone.scala.poi.Row, Set[info.folone.scala.poi.Cell]) = (Row (1)(Set(Cell(1,data), Cell(2,data1))),Set(Cell(1,data), Cell(2,data1)))

scala> (rowLens |= Set(Cell(2, "data1"))).run(Row(1)(Set(Cell(1, "data"), Cell(2, "data2"))))
res21: (info.folone.scala.poi.Row, Set[info.folone.scala.poi.Cell]) = (Row (1)(Set(Cell(1,data), Cell(2,data2), Cell(2,data1))),Set(Cell(1,data), Cell(2,data2), Cell(2,data1)))

scala> (rowLens -= Cell(2, "data1")).run(Row(1)(Set(Cell(1, "data"), Cell(2, "data1"))))
res23: (info.folone.scala.poi.Row, Set[info.folone.scala.poi.Cell]) = (Row (1)(Set(Cell(1,data))),Set(Cell(1,data)))

Mostly using this: https://github.com/scalaz/scalaz/blob/scalaz-seven/core/src/main/scala/scalaz/Lens.scala#L350

@folone
Owner
@folone folone closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.