I'm relatively new to Scala and am trying to update some of my code but am a little stuck on how to make the best use of Scala's features & syntactic sugar to do what I want.
Here's a simplified example of what I have:
def someFunction(searchItem: String, items: Set[SomeType1]): Set[SomeType2] =
items.collect {
case SomeType1(_, someFieldA, _, importantField1, importantField2, _, someSet)
if someFieldA == searchItem && importField1 == somethingElse =>
// do some filtering and mapping
someSet.filter(x => x.something....)
.map { t => SomeType2(.....) }
However I want to be able to add an "else" statement inside the case statement and am having issues:
def someFunction(searchItem: String, items: Set[SomeType1]): Set[SomeType2] =
items.collect {
case SomeType1(_, someFieldA, _, importantField1, importantField2, _, someSet)
if someFieldA == searchItem && importField1 == somethingElse =>
// do some filtering and mapping
someSet.filter(x => x.something....)
.map { t => SomeType2(.....) }
else if someFieldA == somethingElse || someSet.contains("foo") =>
someSet.filter(x => x.something....)
.map { t => SomeType2(.....) }
But it won't compile with that else if in there (it expects a } after .map in the if block...
Is there another way I could do something like this?