4 ms·
Scala version can be written as one-liner as well; losing readability, but it might be ok for fast hacking / prototyping: article.author.flatMap(_.address).fla
by krcz 11y ago
Scala version can be written as one-liner as well; losing readability, but it might be ok for fast hacking / prototyping:
article.author.flatMap(_.address).flatMap(_.city).map(_.toLowerCase).foreach(println)
And in for-comprehension version there is no need to use yield, as we don't need result of println.
- dk8996 11y agoWe work with Scala at our company and this is the style we use. I think that it's something that even a new person to Scala can easy understand.
- Filligree 11y agoHell, I've never used Scala at all, and I can read that.
- closetnerd 11y agoYou can tell that "_.author" is a parameterless lambda?
- Filligree 11y agoUm, no? It takes one parameter. Wouldn't fit into the map type signature otherwise.
- psuter 11y agoAfter 10 years of programming in Scala, I must admit I still don't know which style I prefer.