Why is foreach better than get for Scala Options?
Well, it kind of comes back to “tell, don’t ask”. Consider these two lines: if (opt.isDefined) println(opt.get) // versus opt foreach println In the first case, you are looking inside opt and then reacting depending on what you see. In the second case you are just telling opt what you want done, and let it … Read more