Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Created February 18, 2014 01:25
Show Gist options
  • Save puffnfresh/9062812 to your computer and use it in GitHub Desktop.
Save puffnfresh/9062812 to your computer and use it in GitHub Desktop.
Scala Lenz README

Scala Lenz

This library is a port of Haskell's lens. The goal is to provide functional lenses, isomorphisms, getters and setters.

Examples

Isomorphisms

import lenz._
import scalaz.std.function._
import scalaz.Id.Id

case class MyString(s: String)
val myStringIso = iso((_: MyString).s)(MyString)

val myHelloWorld = MyString("Hello") & myStringIso[=>:, Id] %~ (_ + " world")
// myHelloWorld: MyString = MyString(Hello world)

Getters

import lenz._

val my = ("My", "world") ^\ (_1: Lens$[(String, String), String]).const[String]
// my: String = My

Setters

import lenz._
import scalaz.Id.Id

val helloWorld = ("My", "world") & (_1: Lens$[(String, String), String]).id \~ "Hello"
// helloWorld: (String, String) = (Hello,world)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment