Created
April 4, 2013 18:36
-
-
Save xuwei-k/5312938 to your computer and use it in GitHub Desktop.
shapeless and scalaz lens converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scalaVersion := "2.10.1" | |
libraryDependencies ++= Seq( | |
"org.scalaz" %% "scalaz-core" % "7.0.0-RC1", | |
"com.chuusai" %% "shapeless" % "1.2.4" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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