Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created April 4, 2013 18:36
Show Gist options
  • Save xuwei-k/5312938 to your computer and use it in GitHub Desktop.
Save xuwei-k/5312938 to your computer and use it in GitHub Desktop.
shapeless and scalaz lens converter
scalaVersion := "2.10.1"
libraryDependencies ++= Seq(
"org.scalaz" %% "scalaz-core" % "7.0.0-RC1",
"com.chuusai" %% "shapeless" % "1.2.4"
)
import scalaz.BijectionT.<@>
object LensConverter{
def shapeless2scalaz[A, B](shapelessLens: shapeless.Lens[A, B]): scalaz.Lens[A, B] =
scalaz.LensFamily.lensFamilyg(shapelessLens.set, shapelessLens.get)
def scalaz2shapeless[A, B](scalazLens: scalaz.Lens[A, B]): shapeless.Lens[A, B] =
new shapeless.Lens[A, B]{
def get(a: A): B = scalazLens.get(a)
def set(a: A)(b: B): A = scalazLens.set(a, b)
}
def lensBijection[A, B]: scalaz.Lens[A, B] <@> shapeless.Lens[A, B] = ???
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment