Created
November 30, 2018 15:20
-
-
Save globulon/42d5780789bcd7bf45e56be3ce983715 to your computer and use it in GitHub Desktop.
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
| trait Isomorphism[Arrow[_, _], A, B] { | |
| def to: Arrow[A, B] | |
| def from: Arrow[B, A] | |
| } |
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
| trait Isomorphisms { | |
| type IsoSet[A, B] = Isomorphism[Function1, A, B] | |
| type <=>[A, B] = IsoSet[A, B] | |
| implicit def eitherIsoSafe[A]: Either[List[Throwable], A] <=> Safe[A] = | |
| new (Either[List[Throwable], A] <=> Safe[A]) { | |
| override def to: Either[scala.List[scala.Throwable], A] => Safe[A] = { | |
| case Right(a) => safe(a) | |
| case Left(exs) => Invalid(exs) | |
| } | |
| override def from: Safe[A] => Either[List[Throwable], A] = { | |
| case Valid(a) => Right(a) | |
| case Invalid(exs) => Left(exs) | |
| } | |
| } | |
| trait IsoSetOps[A, B] { | |
| def iso: A <=> B | |
| def self: A | |
| def asT[C](implicit eq: B === C): C = eq.coerce(iso.to(self)) | |
| } | |
| trait ToIsoSetOps { | |
| implicit def toIsoSetOps[A, B](target: A)(implicit tc: A <=> B): IsoSetOps[A, B] = | |
| new IsoSetOps[A, B] { | |
| val self: A = target | |
| val iso: A <=> B = tc | |
| } | |
| } | |
| object iso extends ToIsoSetOps | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment