[英]Scala invocation chaining
你会写:
(ontDrugFormXml \ "VPID").headOption map
(id => graph.addE(vertex, searchDmdVertex(graph, "VMP", id.text), "has")) orElse
(throw new IllegalStateException("VPID required"))
要么:
(ontDrugFormXml \ "VPID").headOption
.map(id => graph.addE(vertex, searchDmdVertex(graph, "VMP", id.text), "has"))
.orElse(throw new IllegalStateException("VPID required"))
哪一个适合你?
无法在http://docs.scala-lang.org/style/method-invocation.html上找到答案
像这样:
(ontDrugFormXml \ "VPID").headOption map { id =>
graph.addE(vertex, searchDmdVertex(graph, "VMP", id.text), "has")
} orElse (throw new IllegalStateException("VPID required"))
scala样式指南需要使用带有函数参数的map
方法的中缀表示法。 参数应与开括号位于同一行,例如在map
旁边。 orElse
应该与它所需的值相同。
Infix,第一选择。 我总是使用中缀符号表示orElse。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.