Skip to content

Instantly share code, notes, and snippets.

@matthandlersux
Created February 1, 2014 12:05
Show Gist options
  • Save matthandlersux/8751399 to your computer and use it in GitHub Desktop.
Save matthandlersux/8751399 to your computer and use it in GitHub Desktop.

Revisions

  1. matt handler created this gist Feb 1, 2014.
    15 changes: 15 additions & 0 deletions gistfile1.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    trait Base[T] {
    val id: Option[String]

    def copyId(id: String): T
    }

    case class Test2(id: Option[String], other: String) extends Base[Test2] {
    def copyId(id: String) = copy(id=Some(id))
    }

    def updateId[T <: Base[T]](obj: T, id: String) = obj.copyId(id)

    val y = Test2(None, "hmm")

    assert(updateId(y, "!!!") == Test2(Some("!!!"), "hmm"))