以下特徵Parser[+T]
是一個特徵,它擴展了接受Input
並返回Result[T]
的函數。特質擴展(A => B)是一種特質擴展功能嗎?
trait Parser[+T] extends (Input => Result[T])
這是正確的嗎?
以下特徵Parser[+T]
是一個特徵,它擴展了接受Input
並返回Result[T]
的函數。特質擴展(A => B)是一種特質擴展功能嗎?
trait Parser[+T] extends (Input => Result[T])
這是正確的嗎?
沒錯。
Input => Result[T]
是Function1[Input, Result[T]]
的快捷方式。 它的abstrat方法
def apply(v1: Input) : Result[T]
其中,當定義將實際的函數執行。
Scala的語法允許稱爲apply
方法被稱爲靜默,即對於某些表達e
,e(x1, ... xn)
將被轉換爲e.apply(x1, ... xn)
幾乎。它將Function [Input,Result [T]]擴展爲以Inputs作爲參數並返回Result [T](不是T)作爲結果的函數的類型。結果[T]將有關成功解析的信息載入T或在解析期間發生的錯誤。