Skip to content

Instantly share code, notes, and snippets.

@debasishg
Created January 1, 2011 20:12
Show Gist options
  • Select an option

  • Save debasishg/761970 to your computer and use it in GitHub Desktop.

Select an option

Save debasishg/761970 to your computer and use it in GitHub Desktop.
Lens can be generated from case classes through compiler plugins ..
scala> import scalaz._
import scalaz._
scala> import Scalaz._
import Scalaz._
scala> case class Address(no: Int, street: String, zip: String)
defined class Address
// this can be generated
scala> val streetLens: Lens[Address, String] = Lens((a: Address) => a.street, (a: Address, s: String) => a.copy(street = s))
streetLens: scalaz.Lens[Address,String] = Lens(<function1>,<function2>)
// similarly for other fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment