Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



We 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.


Hell, I've never used Scala at all, and I can read that.


You can tell that "_.author" is a parameterless lambda?


Um, no? It takes one parameter.

Wouldn't fit into the map type signature otherwise.


After 10 years of programming in Scala, I must admit I still don't know which style I prefer.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: