What is the accepted/recommended syntax for Scala code with lots of method-chaining?

前端 未结 6 1065
死守一世寂寞
死守一世寂寞 2021-02-05 06:29

In Scala I tend to favour writing large chained expressions over many smaller expressions with val assignments. At my company we\'ve sort of evolved a style for th

6条回答
  •  执念已碎
    2021-02-05 06:59

    I usually try to avoid using dot for things like map and filter. So I would probably write it like the following:

    def foo: List[Int] =
      (1 to 100).view map { x =>
        x + 3 } filter { x =>
        x > 10 } flatMap { table.get } take(3) toList
    

    The leading dot notation is very readable. I might start using that.

提交回复
热议问题