gpt4 book ai didi

scala - Scala升降机: Box openOr does not seem to work

转载 作者:行者123 更新时间:2023-12-02 10:45:42 25 4
gpt4 key购买 nike

我正在阅读“Exploring Lift”一书,并且尝试了其中一个示例片段-此处唯一的区别是我不使用MegaProtoUser类,而是使用了自己的类。但是,我遇到以下问题。

这是我的代码段:

User.currentUser.map(user =>
user.projects.flatMap(project => {
bind("e", chooseTemplate("project", "entry", in),
"name" -> Text(project.name.is),
"actions" -> {
SHtml.link("/manageProjects", () => project.delete_!, Text("Delete")) ++ Text(" ") ++
SHtml.link("/editProject", () => currentAccountVar(project), Text("Edit"))
})
})) openOr Text("You are not logged in.")

这是编译器错误:
inferred type arguments [Seq[scala.xml.Node]{def seq: Seq[scala.xml.Node]{def companion: scala.collection.generic.GenericCompanion[Seq[Any]]}; def companion: scala.collection.generic.GenericCompanion[Seq[Any]]}] do not conform to method openOr's type parameter bounds [B >: scala.collection.mutable.Buffer[scala.xml.Node]]  

type mismatch; found : scala.xml.Text required: Seq[scala.xml.Node]{def seq: Seq[scala.xml.Node]{def companion: scala.collection.generic.GenericCompanion[Seq[Any]]}; def companion: scala.collection.generic.GenericCompanion[Seq[Any]]}

如果我用open_替换openOr Text(“您尚未登录。”)。然后就可以了。

为什么在这种情况下我不能使用openOr,这个错误是什么意思?正确的方法是什么?

最佳答案

该错误意味着编译器需要一个序列,但是找到了一个元素。尝试

 List(Text(....))

而不只是
Text(....)

关于scala - Scala升降机: Box openOr does not seem to work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6894460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com