-
-
Save paulp/463986 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
// The comments show everything I type: | |
// ccc<tab> | |
class Class(arguments) { | |
override def hashCode = 0 arguments | |
override def equals(other: Any) = Class.unapply(this) == Class.unapply(other) | |
override def canEqual(other: Any) = other.isInstanceOf[Class] | |
} | |
object Class { | |
def apply(arguments): Class = new Class(arguments) | |
def unapply(other: Any) = other match { | |
case x: Class => import x._ ; Some(arguments) | |
case _ => None | |
} | |
} | |
// Foobar | |
class Foobar(arguments) { | |
override def hashCode = 0 arguments | |
override def equals(other: Any) = Foobar.unapply(this) == Foobar.unapply(other) | |
override def canEqual(other: Any) = other.isInstanceOf[Foobar] | |
} | |
object Foobar { | |
def apply(arguments): Foobar = new Foobar(arguments) | |
def unapply(other: Any) = other match { | |
case x: Foobar => import x._ ; Some(arguments) | |
case _ => None | |
} | |
} | |
// <tab>x: Int, bippy: List[String], hi: Float | |
class Foobar(val x: Int, val bippy: List[String], val hi: Float) { | |
override def hashCode = 0 + x.## + bippy.## + hi.## | |
override def equals(other: Any) = Foobar.unapply(this) == Foobar.unapply(other) | |
override def canEqual(other: Any) = other.isInstanceOf[Foobar] | |
} | |
object Foobar { | |
def apply(x: Int, bippy: List[String], hi: Float): Foobar = new Foobar(x, bippy, hi) | |
def unapply(other: Any) = other match { | |
case x: Foobar => import x._ ; Some(x, bippy, hi) | |
case _ => None | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment