Skip to content

Nanolens is tiny and experimental lens library for Scala 3

License

Notifications You must be signed in to change notification settings

aoiroaoino/nanolens

Repository files navigation

nanolens

CI Maven Central

Nanolens is tiny and experimental lens library for Scala 3

type Lens[S, A] = [F[_]] => Functor[F] ?=> (A => F[A]) => S => F[S]

type Prism[S, T, A, B] = [P[_, _], F[_]] => (Choice[P], Applicative[F]) ?=>
  P[A, F[B]] => P[S, F[T]]

Installation

libraryDependencies += "dev.aoiroaoino" %% "nanolens" % "[version]"

Example

import dev.aoiroaoino.nanolens._

case class User(id: Int, name: String, address: Address)
case class Address(street: String)

def address: Lens[User, Address] =
  Lens[User, Address](_.address)(u => a => u.copy(address = a))

def street: Lens[Address, String] =
  Lens[Address, String](_.street)(a => s => a.copy(street = s))
  
// ===
  
val user = User(42, "John", Address("street"))

user $ (address ~ street).modify(_.toUpperCase)
// => User(42,John,Address(STREET))

user $ (address ~ street).get
// => street

About

Nanolens is tiny and experimental lens library for Scala 3

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages