Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is trait extends (A => B) a trait extending function?

Tags:

scala

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?

like image 475
Jon Strayer Avatar asked Mar 30 '12 16:03

Jon Strayer


2 Answers

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)

like image 68
Didier Dupont Avatar answered Oct 17 '22 05:10

Didier Dupont


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.

like image 28
James Iry Avatar answered Oct 17 '22 04:10

James Iry