【发布时间】:2021-07-30 18:49:21
【问题描述】:
我正在使用 scala Map#get 函数,并且对于每个准确的查询,它都返回为 Some[String]
有没有一种简单的方法可以删除Some?
例子:
def searchDefs{
print("What Word would you like defined? ")
val selection = readLine
println(selection + ":\n\t" + definitionMap.get(selection))
}
当我使用此方法并使用以下输入时:
What Word would you like defined? Ontology
返回值为:
Ontology:
Some(A set of representational primitives with which to model a domain of knowledge or discourse.)
我想删除它周围的 Some()。
有什么建议吗?
【问题讨论】:
-
Option的奇妙之处在于它迫使您处理None案件。