An open API service indexing awesome lists of open source software.

https://github.com/encalmo/lens

Library for Scala > 3.6.2 providing Lens[R,V] typeclass derivation
https://github.com/encalmo/lens

lenses scala scala3 scala3-metaprogramming

Last synced: 3 months ago
JSON representation

Library for Scala > 3.6.2 providing Lens[R,V] typeclass derivation

Awesome Lists containing this project

README

        

![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white) ![Maven Central Version](https://img.shields.io/maven-central/v/org.encalmo/lens_3?style=for-the-badge) Scaladoc

# lens

Scala library providing Lens[R,V] typeclass derivation.

## Dependencies

- [Scala](https://www.scala-lang.org/) >= 3.6.2

## Usage

Use with SBT

libraryDependencies += "org.encalmo" % "lens_3" % "0.9.0"

or with SCALA-CLI

//> using dep org.encalmo::lens:0.9.2

## Examples

```scala

case class Person(firstName: String, lastName: String, address: Address)
case class Address(street1: String, street2: Option[String] = None, postcode: String, town: String, country: String)

val townLens = Lens[Person].address.town

val mike = Person("Mike","Hart", Address("1 Abbey Road", None, "BN15 KJ", "Exeter", "United Kingdom"))

val town = townLens.get(mike)
townLens.set(mike)("Derby")
townLens.update(mike, town => town.toUpperCase())

```