Binary operator with Option arguments

前端 未结 5 850
渐次进展
渐次进展 2021-02-09 06:49

In scala, how do I define addition over two Option arguments? Just to be specific, let\'s say they\'re wrappers for Int types (I\'m actually working with maps of do

5条回答
  •  灰色年华
    2021-02-09 07:45

    def addOpts(xs: Option[Int]*) = xs.flatten.sum
    

    This will work for any number of inputs.

提交回复
热议问题