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

前端 未结 6 1064
死守一世寂寞
死守一世寂寞 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:54

    I wrap the entire expression into a set of parenthesis to group things and avoid dots if possible,

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

提交回复
热议问题