Skip to content

Instantly share code, notes, and snippets.

@mindscratch
Created March 7, 2014 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mindscratch/9409980 to your computer and use it in GitHub Desktop.
Save mindscratch/9409980 to your computer and use it in GitHub Desktop.
learning scala

march 6, 2014

What's the difference between val and var?

  • A val variable can not have it's value changed, but a var variable can.

march 7, 2014

What's the deal with implicit val?

  • Marking a value as implicit allows it to be used by functions that accept implicit parameters.
  def fn(x: Int)(implicit y: Boolean) = if(y) x else - x

  fn(1)(true) // returns 1
  implicit val b = false
  fn(1) // returns -1 using b as the argument for the implicit argument
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment