リファクタリングvalメソッドの結果をコンパイル時エラー
-
19-09-2019 - |
質問
わたしは現在
def list(node: NodeSeq): NodeSeq = {
val all = Thing.findAll.flatMap({
thing => bind("thing", chooseTemplate("thing", "entry", node),
"desc" -> Text(thing.desc.is),
"creator" -> thing.creatorName.getOrElse("UNKNOWN"),
"delete" -> SHtml.link("/test", () => delete(thing), Text("delete"))
)
})
all match {
case Nil => <span>No things</span>
case _ => <ol>{bind("thing", node, "entry" -> all)}</ol>
}
}
いてみましたrefactorで
def listItemHelper(node: NodeSeq): List[NodeSeq] = {
Thing.findAll.flatMap({
thing => bind("thing", chooseTemplate("thing", "entry", node),
"desc" -> Text(thing.desc.is),
"creator" -> thing.creatorName.getOrElse("UNKNOWN"),
"delete" -> SHtml.link("/test", () => delete(thing), Text("delete"))
)
})
}
def list(node: NodeSeq): NodeSeq = {
val all = listItemHelper(node)
all match {
case Nil => <span>No things</span>
case all: List[NodeSeq] => <ol>{bind("thing", node, "entry" -> all)}</ol>
case _ => <span>wtf</span>
}
}
ものを取得します。私は追跡すべての戻り値の型とんどのマリファクタリングするようになっているようにする内蔵しています。もっ加試合の例では、コードを整理)をさせて頂いていたのを選択し、適切なタイプです。
/Users/trenton/projects/sc2/supperclub/src/main/scala/com/runbam/snippet/Whyme.scala:37: error: overloaded method value -> with alternatives [T <: net.liftweb.util.Bindable](T with net.liftweb.util.Bindable)net.liftweb.util.Helpers.TheBindableBindParam[T] <and> (Boolean)net.liftweb.util.Helpers.BooleanBindParam <and> (Long)net.liftweb.util.Helpers.LongBindParam <and> (Int)net.liftweb.util.Helpers.IntBindParam <and> (Symbol)net.liftweb.util.Helpers.SymbolBindParam <and> (Option[scala.xml.NodeSeq])net.liftweb.util.Helpers.OptionBindParam <and> (net.liftweb.util.Box[scala.xml.NodeSeq])net.liftweb.util.Helpers.BoxBindParam <and> ((scala.xml.NodeSeq) => scala.xml.NodeSeq)net.liftweb.util.Helpers.FuncBindParam <and> (Seq[scala.xml.Node])net.liftweb.util.Helpers.TheBindParam <and> (scala.xml.Node)net.liftweb.util.Helpers.TheBindParam <and> (scala.xml.Text)net.liftweb.util.Helpers.TheBindParam <and> (scala.xml.NodeSeq)net.liftweb.util.Helpers.TheBindParam <and> (String)net.liftweb.util.Helpers.TheStrBindParam cannot be applied to (List[scala.xml.NodeSeq])
case all: List[NodeSeq] => <ol>{bind("thing", node, "entry" -> all)}</ol>
^
解決
こちらはどのように私の脳構文解析エラーメッセージ...
error: overloaded method value ->
このメソッドの名前は、'->'.
with alternatives
うまで指定可能なパラメータ->内のbind()機能です。
[T <: net.liftweb.util.Bindable](T with net.liftweb.util.Bindable)net.liftweb.util.Helpers.TheBindableBindParam[T]
こうなる実施の形質の結合性は公正なゲームです。
<and> (Boolean)net.liftweb.util.Helpers.BooleanBindParam
<and> (Long)net.liftweb.util.Helpers.LongBindParam
<and> (Int)net.liftweb.util.Helpers.IntBindParam
<and> (Symbol)net.liftweb.util.Helpers.SymbolBindParam
<and> (Option[scala.xml.NodeSeq])net.liftweb.util.Helpers.OptionBindParam
<and> (net.liftweb.util.Box[scala.xml.NodeSeq])net.liftweb.util.Helpers.BoxBindParam
バンチの種類-特定します。
<and> ((scala.xml.NodeSeq) => scala.xml.NodeSeq)net.liftweb.util.Helpers.FuncBindParam
<and> (Seq[scala.xml.Node])net.liftweb.util.Helpers.TheBindParam
<and> (scala.xml.Node)net.liftweb.util.Helpers.TheBindParam
<and> (scala.xml.Text)net.liftweb.util.Helpers.TheBindParam
<and> (scala.xml.NodeSeq)net.liftweb.util.Helpers.TheBindParam
<and> (String)net.liftweb.util.Helpers.TheStrBindParam
あっ!!ノード関連のもの。当社で有効なオプションかNodeSeq、配列番号[ノード、テキストノード
cannot be applied to (List[scala.xml.NodeSeq])
ようなリスト[NodeSeq"でなくてはならない有効なオプションです。
こだく個人NodeSeqのリストを拘束するものです。Are you sure youたリストを返しからヘルパーできますか?
他のヒント
私はNodeSeqは、配列[ノード]を拡張することを確認することができなかったので、私は、抽出法上の間違った戻り値の型を持っていました。それを変更する
def listItemHelper(node: NodeSeq): NodeSeq = {
Thing.findAll.flatMap({
thing => bind("thing", chooseTemplate("thing", "entry", node),
"desc" -> Text(thing.desc.is),
"creator" -> thing.creatorName.getOrElse("UNKNOWN"),
"delete" -> SHtml.link("/test", () => delete(thing), Text("delete"))
)
})
}
def list(node: NodeSeq): NodeSeq = {
val all = listItemHelper(node)
all.length match {
case 0 => <span>No things</span>
case _ => <ol>{bind("thing", node, "entry" -> all)}</ol>
}
}
作品ます。
1つの問題は、あなたの試合は本当にどんな意味がないということです。他の可能性はありません。
all match {
case Nil => //if list is empty
case nonEmptyList => //if list is not empty
}
もちろんあなたも行うことができます:
case Nil =>
case x :: Nil => //list with only a head
case x :: xs => //head :: tail
注意点として、動作しませんあなたのコード内の1つのものがあります:
case all: List[NodeSeq]
そのためのの型消去のは、all
、List[NodeSeq]
、List[String]
または何-持っている - あなたをリストList[AnyRef]
かどうか、実行時に、テストする方法はありません。私はあなたがそのライン上の警告になって、あなたはそれがに関する警告ですか理解していないので、それを無視しなければならないかなり確信している(少なくとも、それは私が、このような警告:)を得たときに私に何が起こったのです。正しい行は次のようになります:
case all: List[_]
List
の任意の種類を受け入れるだろう。あなたが興味を持っている場合、それについて少し詳細を参照するタイプの消去とスカラ座での私の質問を検索します。