Coding Style - Ordering Expressions in Blocks in Scala

Since I started programming in Scala, I gravitated towards what seems like a natural coding style in this language, which is easiest to explain with a simple example:

val a = {
def f1(p : Int) = ...
def f2(p : Int) =  ...
f1(12) * f2(100)
}

As you can see, the multiplication of values, which, if you want to understand the code, is the first operation that you must study, should not be found until the last line. Instead, you need to first read the puzzle pieces (functions f1, f2) before you can see how they are organized. For me, this makes it difficult to read the code. How do you deal with this problem - or maybe you do not find it a problem?

+1
source share
1 answer

-, where, :

val a = (f1(12) * f2(100)) where {
  def f1(x : Int) = x + 1
  def f2(x : Int) = x + 2
}

. , f1 f2 . , , typecheck . , , - , !

, , ( ) - - , , !

: , . github. , , :

  val result = where ( f1(1) * f2(2), {
    def f1(x : Int) = x + 1
    def f2(x : Int) = x + 2
  })

, infix Scala - , - (f1 (1) * f2 (2)), . , , , . , !

+1

All Articles