I’m just beginning in scala and I’m converting some java code into scala and trying to make it nice and functionally elegant.
I have the following code containing a method (getRequiredUploadPathKeys) which gives a union of all of the path keys required by all of the available path templates in MyClass.
trait PathTemplate {
def getRequiredPathKeys:Set[PathKey]
}
class MyClass(accessPaths:Set[PathTemplate], targetPath:PathTemplate){
def getAllRequiredPathKeys: Set[PathKey] = {
val pathKeys = HashSet[PathKey]()
pathKeys.addAll(targetPath.getRequiredPathKeys)
for (accessTemp <- accessPaths) {
pathKeys.addAll(accessTemp.getRequiredPathKeys)
}
return pathKeys
}
}
This method just seems like it could be much more concise in scala. Can anyone point me towards how to get it there?
Thanks,
Paul
Do you mean something like: