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