Hello, I’m experimenting with Optics, and I have s...
# arrow
d
Hello, I’m experimenting with Optics, and I have something like
Copy code
playerFlow.map { player ->
  val firstNameLens = Player.name.first
  firstNameLens.set(player, "John")
}
If I want to modify also the last name, is there a nicer way than this?
Copy code
playerFlow.map { player ->
  val firstNameLens = Player.name.first
  val lastNameLens = Player.name.last
  val a = firstNameLens.set(player, "John")
  lastNameLens.set(a, "Doe")
}
I chose a more functional approach with
let
Copy code
player
  .let { fnLens.set(it, "John") }
  .let { lnLens.set(it, "Doe") }
w
On 1.1.3, you could use something like
Copy code
player.copy {
  Player.name.first set "John"
  Player.name.last set "Doe"
}
d
Wow! This is great! I’m going to try it! Thank you