Seven ways to write the same code snippet
Here are eight ways to write the exactly same code. Some are easier to read than others and all are a variation of a code I've seen in a real code base. My personal favorite is #7, what's yours?
#1 One liner
DAO.filter { it.name == "foo" }.map { it.company }.toSet()
#2 two lines, three operations
DAO.filter { it.name == "foo" }
.map { it.company }.toSet()
#3 Evaluation on it's own line
DAO.filter {
it.name == "foo"
}.map { it.company }.toSet()
#4 Each operation and evaluation on their own lines
DAO.filter {
it.name == "foo"
}.map { it.company }
.toSet()
#5 All function calls and evaluation on their own lines
DAO
.filter {
it.name == "foo"
}.map { it.company }
.toSet()
#6 Everything on it's own line
DAO
.filter {
it.name == "foo"
}
.map { it.company }
.toSet()
#7 All function calls on their own lines
DAO
.filter { it.name == "foo" }
.map { it.company }
.toSet()
#8 Three lines where each operation is on it's own line
DAO.filter { it.name == "foo" }
.map { it.company }
.toSet()