February 2018
Intermediate to advanced
350 pages
7h 35m
English
Once Arrow's code generation is configured, you can add the @lenses annotation to the data classes that you want to have lenses generated for:
import arrow.lensesimport arrow.optics.Lensimport arrow.optics.modifytypealias GB = Int@lenses data class Memory(val size: GB)@lenses data class MotherBoard(val brand: String, val memory: Memory)@lenses data class Laptop(val price: Double, val motherBoard: MotherBoard)fun main(args: Array<String>) { val laptopX8 = Laptop(500.0, MotherBoard("X", Memory(8))) val laptopMemorySize: Lens<Laptop, GB> = laptopMotherBoard() compose motherBoardMemory() compose memorySize() val laptopX16 = laptopMemorySize.modify(laptopPrice().set(laptopX8, 780.0)) { size -> size * 2 } println("laptopX16 = ...
Read now
Unlock full access