dgadiraju
5/14/2017 - 4:27 AM

set-additions-removals-operations.scala

//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")