The following trait Parser[+T]
is a trait that extends a function that accepts an Input
and returns a Result[T]
.
trait Parser[+T] extends (Input => Result[T])
Is that correct?
Right.
Input => Result[T]
is a shortcut for Function1[Input, Result[T]]
. It has an abstrat method
def apply(v1: Input) : Result[T]
which when defined will be the actual function implementation.
Scala syntax allows methods called apply
to be called silently, that is for some expression e
, e(x1, ... xn)
will be translated to e.apply(x1, ... xn)
Almost. It extends Function[Input, Result[T]]
- the type of function that takes Input
as argument and returns Result[T]
(not T
) as result. Result[T]
carries information about a successful parse into a T
or an error that occurs during parse.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.