Getting Value of Either

前端 未结 4 1174
长情又很酷
长情又很酷 2021-01-01 11:54

Besides using match, is there an Option-like way to getOrElse the actual content of the Right or Left value?



        
4条回答
  •  臣服心动
    2021-01-01 12:19

    In Scala 2.12 there is a getOrElse method for getting the "right" value but you cannot use it for the "left" value directly. However, you can do it like this: e.swap.getOrElse(42).

提交回复
热议问题