【发布时间】:2019-11-01 10:11:11
【问题描述】:
这种常见的模式感觉有点冗长:
if (condition)
Some(result)
else None
我正在考虑使用函数来简化:
def on[A](cond: Boolean)(f: => A) = if (cond) Some(f) else None
这将最上面的例子简化为:
on (condition) { result }
这样的东西已经存在了吗?或者这是矫枉过正?
【问题讨论】:
标签: scala