Releases: sagifogel/Proptics
Releases · sagifogel/Proptics
v0.3.0
- addition of Scala 2.x macros for Lens/ALens and Prism/APrism (#112) @sagifogel
import proptics.Lens
import proptics.macros.GLens
final case class Person(name: String, address: Address)
final case class Address(city: String, street: Street)
final case class Street(name: String, number: Int)
val personNameLens: Lens[Person, Int] = GLens[Person](_.address.street.number)
val person = Person("Walter White", Address("Albuquerque", Street("Negra Arroyo Lane", 9)))
personNameLens.set(308)(person)
// Person(Walter White,Address(Albuquerque,Street(Negra Arroyo Lane,308)))
import proptics.Prsims
import proptics.macros.GPrism
sealed trait Request
final case class GET(path: List[String]) extends Request
final case class POST(path: List[String], body: String) extends Request
val webServerPrism = GPrism[Request, GET]
webServerPrism.preview(GET(List("path")))
// Some(GET(List(path)))
webServerPrism.preview(POST(List("path"), "body"))
// None
- addition of andThen for all optics (#113 ) @sagifogel
v0.2.1
What's Changed
- addition of unsafePartsOf (#101) @sagifogel
unsafePartsOf
is similar to partsOf
but can change the type of the focus
Traversal_[S, T, A, B] => Lens[S, T, List[A], List[B]]
Using unsafePartsOf
we can set the elements of a List to a different type
import proptics.instances.partsOf._
import proptics.std.tuple._1P
import proptics.{Lens, Traversal}
val unsafePartsOfFromTraversal =
Traversal_.fromTraverse[List, (String, Int), (Boolean, Int)]
.andThen(_1P[String, Boolean, Int])
.unsafePartsOf
val target = List("A", "B", "C").zipWithIndex
// List((A,0), (B,1), (C,2))
unsafePartsOfFromTraversal.set(List(true, false, true))(target)
// List((true,0), (false,1), (true,2))
It’s called unsafe, because it will crash if we set with the wrong number of elements
unsafePartsOfFromTraversal.set(List(true, false))(target)
// java.lang.IllegalArgumentException: Not enough elements were supplied
v0.2.0
What's Changed
- addition of partsOf (#95) @sagifogel
partsOf
converts a Traversal
into a Lens
over a list of the Traversal
’s foci
Traversal[S, A] => Lens[S, List[A]]
Using partsOf
we can set the elements of a List
import proptics.instances.field1._
import proptics.instances.partsOf._
import proptics.std.tuple._1
import proptics.syntax.traversal._
import proptics.{Lens, Traversal}
val partsOfFromTraversal =
Traversal.fromTraverse[List, (String, Int)]
.andThen(_1[String, Int])
.partsOf
val target = List("A", "B", "C").zipWithIndex
// List((A,0), (B,1), (C,2))
partsOfFromTraversal.set(List("C", "A", "T"))(target)
// List((C,0), (A,1), (T,2))