I think we have been over this a few times already?
If you are going to point out that I made some mistakes, please be constructive so can actually change it and learn something from it.
The entire rest of the post was explaining what you did wrong.
You would almost think I actually do not know the language and thus try to prevent creating to much of mess.
You're not learning the language by avoiding its mechanics. You don't need to write perfect code the first time, or even good code the first time, but if you actually want to learn the language, you should be making an active effort to actually learn how the language is used and what the sort of code that people expect is. If you need some lints, I'm sure you can find a Scala linter online. General rule of thumb though: You never need to chain maps because instead, you could map the composition of those functions. Similar rules apply to other higher-order functions.
Oh thank you, I instantly understood what I have been doing wrong the whole time.
Oh wait, it did not help at all.
What you've been doing wrong, as I've said before, is that you've been writing entirely object-oriented code in a hybrid language that's main strength is its ability to use functional idioms. The clarification I was adding was that while you keep responding and talking about foreach, in most cases, you'd actually want to use a map or fold instead of a foreach. If you didn't refuse to listen at all, this would actually prove a useful piece of advice.
Yeah, so basically the opposite of what I (tried to?) explain.
Why use multiple maps, folds and filters while a single for and filter does what you want.
My point exactly is that you can use a single map or fold instead of a single for loop. Your complaint about using multiple maps is akin to saying "For loops suck because you could use three of them to implement something you could do in one for loop." Bad programming isn't a reason not to use something, and it's not a reason not to learn how to do something useful.
People do this because they think it looks 'fancy', yet I do not have enough knowledge to simplify it enough without using the for syntax.
You don't pull the knowledge out of thin air. You learn how to write good code using higher-order functions by doing it, not by totally ignoring it as a language feature. Anybody who's writing higher-order functions because they look "fancy" is probably not a very good programmer, but I think you're wrong that this is the general trend. People write higher-order functions because they're an effective way of encapsulating common, but somewhat complex semantics into simple, consistent idioms.
Hmm, if there only was of telling somebody I already fully understood that in the first place so they wont come up telling me exactly what I tried to avoid them telling me.
If you really knew this already, you wouldn't have tried to put that point as an aside. The necessity to understand standard library functions is important, and incredibly relevant in this discussion.
Thank you fine sir, by actually figuring out what I tried to say by contradicting yourself.
I did not contradict myself at all. I said you should use map and fold over foreach, and I also said that map and fold are the bread and butter of functional programming. Both of these things are true, and both of these things are mutually consistent. I'm not sure where exactly you think I contradicted myself, but you're clearly lacking in English literacy. So, maybe you should work on that before you start trying to work on learning how to actually program.
Using functional style for things like iteration can actually be very efficient. For example, Rust uses functional style iterators and yet, thanks to optimizations, it runs just as fast as a carefully crafted C-style loop. Functional style is not slow, but an implementation of it can be. Hence why I said to benchmark it first.
For the record, Scala, Haskell, and any other reasonable functional language perform similar optimizations. There's virtually no performance difference between one map and two maps. Any performance difference is so negligible that other factors (in Scala's case, especially the GC) will outpace it. Go ahead, try it yourself.