Created
November 4, 2020 10:46
-
-
Save Yotamho/86941428651e90d758a5db6f26313dc8 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
| object PatternMatchingMorphBehaviour { | |
| // Intention is to morph behaviour of pattern matching, | |
| // in this example I want to make an unapplied value's "equals" | |
| // method always return true if the value it compares against is a None | |
| // (and additionally, if it is a Some, to extract to value out of the Some) | |
| // this way I can do like a "runtime optional matcher" | |
| trait EqualIfNone { | |
| override def equals(obj: Any): Boolean = obj match { | |
| case Some(x) => super.equals(x) | |
| case None => true | |
| case x => super.equals(x) | |
| } | |
| } | |
| object OptionalMatcher { | |
| def unapply[T](arg: T): Option[T] = Some(???) //can't work because I can't override the equals of the object. | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment