Skip to content

v0.2.1

Compare
Choose a tag to compare
@github-actions github-actions released this 26 May 17:39
· 476 commits to master since this release
fbf8953

What's Changed

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