Implementing ifTrue, ifFalse, ifSome, ifNone, etc. in Scala to avoid if(…) and simple pattern matching

前端 未结 3 616
夕颜
夕颜 2020-12-08 17:44

In Scala, I have progressively lost my Java/C habit of thinking in a control-flow oriented way, and got used to go ahead and get the object I\'m interested in first, and the

3条回答
  •  忘掉有多难
    2020-12-08 18:11

    Why don't just use it like this:

    val idiomaticVariable = if (condition) { 
        firstExpression
      } else { 
        secondExpression 
      } 
    

    ?

    IMO, its very idiomatic! :)

提交回复
热议问题