Some scala issue during Code manipulation

I really don’t know what you’re trying to do with your foreach loop.

“foreach” is a method that returns Unit (void in Java) and is only intended for side effecting.
As it doesn’t return anything, there’s no way to chain what you’re doing here with a scenario.