Last active
December 10, 2015 18:08
-
-
Save johnynek/4472451 to your computer and use it in GitHub Desktop.
ExceptionalBijection
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
def orElse[A,B](fna: A => Option[B])(fni: B => Option[A])(implicit bi: Bijection[A,B]): Bijection[A,B] = | |
new Bijection[A,B] { | |
def apply(a: A) = fna(a).getOrElse(bij(a)) | |
override invert(b: B) = fni(b).getOrElse(bij.invert(b)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment