Skip to content

Instantly share code, notes, and snippets.

@dgadiraju
Last active May 14, 2017 05:15
Show Gist options
  • Save dgadiraju/336dd9ffb231ca2ffe1aa5df7c28c81f to your computer and use it in GitHub Desktop.
Save dgadiraju/336dd9ffb231ca2ffe1aa5df7c28c81f to your computer and use it in GitHub Desktop.
//os is of type immutable set,
//hence elements cannot be added to set
//+=, ++=, -=, --= will not work
val os = Set(
Order(1, "2017-01-01", 100, "COMPLETE"),
Order(2, "2017-01-01", 20, "CLOSED")
)
//Creating new set by adding element
os + Order(3, "2017-01-01", 301, "PENDING")
//We can add elements using +=, ++=, -=, --=
val os = collection.mutable.Set(
Order(1, "2017-01-01", 100, "COMPLETE"),
Order(2, "2017-01-01", 20, "CLOSED")
)
//+=, ++=, -=, --= will work to manipulate mutable sets
os += Order(3, "2017-01-01", 301, "PENDING")
//But below statement will not work
// as we are trying to assign to immutable os
os = os + Order(4, "2017-01-01", 301, "PENDING")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment