- Describe two ways to make it possible for some resource, R, to be used together with the scala.util.Using resource management utility.
Let R extend java.lang.AutoCloseable. This will allow existing implicit conversion from AutoCloseable into Resource to be applied to R.
Provide an implicit implementation of Resource[R].
- How can Set and List be compared?
Equality is not defined between Set and List, hence we have to use the sameElements method in one of two ways, directly on List or on the iterator of Set, as shown in the following snippet:
val set = Set(1,2,3)
val list = List(1,2,3)
set == list // false
set.iterator.sameElements(list) // true
list.sameElements(set) // true
Another possibility is to utilize the corresponds operation in combination with the equality checking function. This works similar in either direction:
scala> set.corresponds(list)(_ == _)
res2...