On 5/14/12 5:06 PM, Heiko Seeberger wrote:
> Hi,
>
> Some questions:
>
> (I)
> Why do Future.onSuccess and Future.onFailure take a PartialFunction
> instead of a function? If it were a function the code could be more
> concise.
>
> val f: Future[List[String]] = ...
> f onSuccess {
> case posts => posts foreach println
> }
>
> could be rewritten:
>
> val f: Future[List[String]] = ...
> f onSuccess (_ foreach println)
>
> (II)
> Why does Future.foreach have a type parameter? Wouldn't
> Future.foreach(f: T => Any): Unit be simpler and equally good?
>
We could have alternatively have:
def foreach(f: T => Unit)
but then calling:
val func = (x: Int) => {println(); x * 2}
val f = future { 1 }
f.foreach(func)
wouldn't work.
I guess def foreach(f: T => Any) is an ok alternative, but with the:
def foreach[U](f: T => U): Unit
we're more in sync with the collections which have this signature.
So, what are the type inference issues with foreach(f: T => Any)? I must
have missed something.
Thanks,
Alex
--
Aleksandar Prokopec,
Doctoral Assistant
LAMP, IC, EPFL
http://people.epfl.ch/aleksandar.prokopec