Skip to content

Instantly share code, notes, and snippets.

@orionll
Last active December 26, 2015 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save orionll/7079552 to your computer and use it in GitHub Desktop.
Save orionll/7079552 to your computer and use it in GitHub Desktop.
object World extends App {
val pnt = Point(10, 10)
val str: String = pnt(toString)
val x: Int = pnt(getX)
val pnt2: Point = pnt(setX)(20)
val pnt3: Point = pnt(setXY)(20, 19)
println(str)
println(x)
println(pnt2)
println(pnt3)
def toString(point: Point): String = point.toString
/** Sets only x */
def setX(point: Point)(newX: Int) = point.copy(x = newX)
/** Sets x and y */
def setXY(point: Point)(newXY: (Int, Int)): Point = point.copy(x = newXY._1, y = newXY._2)
/** Gets x */
def getX(point: Point): Int = point.x
}
case class Point(x: Int, y: Int) {
def apply[A](f: Point => A): A = f(this)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment