Reputation: 11741
I'm trying to create a simple Iteratee using Play2 on the REPL based on this. But I get a missing parameters
error. But if I provide a type parameter for ele
it works. Can someone explain this ?
scala> import play.api.libs.iteratee._
import play.api.libs.iteratee._
scala> import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.ExecutionContext.Implicits.global
scala> val i = Iteratee.fold(0){ ( acc, ele ) => acc + ele }
<console>:15: error: missing parameter type
val i = Iteratee.fold(0){ ( acc, ele ) => acc + ele }
^
scala> val i = Iteratee.fold(0){ ( acc, ele:Int ) => acc + ele }
i: play.api.libs.iteratee.Iteratee[Int,Int] = play.api.libs.iteratee.ContIteratee@3feaaa9b
Upvotes: 1
Views: 56
Reputation: 139038
Scala's type inference isn't smart enough to say "oh, you wrote acc + ele
and I know that acc
is an integer, so ele
must also be an integer".
In context you often won't need the extra type annotation. For example, this compiles just fine:
Enumerator(1, 2, 3).run(Iteratee.fold(0) { (acc, ele) => acc + ele })
Or this:
val i: Iteratee[Int, Int] = Iteratee.fold(0) { (acc, ele) => acc + ele }
But without some extra context you're just going to have to provide that : Int
.
Upvotes: 2