Created
October 29, 2014 23:31
-
-
Save shajra/a66dd7fbc276b58f1942 to your computer and use it in GitHub Desktop.
This file contains 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
package actionstat.extn.pirate | |
import io.mth.pirate.Flag | |
import io.mth.pirate.Flag._ | |
import scalaz.Isomorphism.{<=>, Iso} | |
object Implicits { | |
implicit def iso[A, B](implicit iso: A <=> B) | |
: Flag[A] <=> Flag[B] = { | |
def endoB(endoA: A => A): B => B = iso.from andThen endoA andThen iso.to | |
def endoA(endoB: B => B): A => A = iso.to andThen endoB andThen iso.from | |
def endoB1(endoA: (A, String) => A): (B, String) => B = | |
(b, s) => iso.to(endoA(iso.from(b), s)) | |
def endoA1(endoB: (B, String) => B): (A, String) => A = | |
(a, s) => iso.from(endoB(iso.to(a), s)) | |
new Iso[Function1, Flag[A], Flag[B]] { | |
def to: Flag[A] => Flag[B] = | |
flagA => | |
flagA.fold( | |
(s, l, d, f) => flag(s, l, d)(endoB(f)), | |
(s, d, f) => short(s, d)(endoB(f)), | |
(l, d, f) => long(l, d)(endoB(f)), | |
(s, l, d, m, f) => flag1(s, l, d, m)(endoB1(f)), | |
(s, d, m, f) => short1(s, d, m)(endoB1(f)), | |
(l, d, m, f) => long1(l, d, m)(endoB1(f))) | |
def from: Flag[B] => Flag[A] = | |
flagB => | |
flagB.fold( | |
(s, l, d, f) => flag(s, l, d)(endoA(f)), | |
(s, d, f) => short(s, d)(endoA(f)), | |
(l, d, f) => long(l, d)(endoA(f)), | |
(s, l, d, m, f) => flag1(s, l, d, m)(endoA1(f)), | |
(s, d, m, f) => short1(s, d, m)(endoA1(f)), | |
(l, d, m, f) => long1(l, d, m)(endoA1(f))) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment