help simplifiing types

28 views
Skip to first unread message

marcos rebelo

unread,
Apr 16, 2017, 1:19:11 AM4/16/17
to scala-user
I have this method:

def withUploadStream[T, OS <: OutputStream](
        path: String,
        osCB: OutputStream => OS = identity[OutputStream] _
    )(
        cb: OS => T
    )(
        implicit ec: ExecutionContext
    ): Future[T] = {
   ...
}

I'm getting insane that I can't simplify the line:

        osCB: OutputStream => OS = identity[OutputStream] _

Seems like I need to repeat this OutputStream 2x. Is it possible to get read of it?

Best
Marcos

Naftoli Gugenheim

unread,
Apr 16, 2017, 2:15:32 AM4/16/17
to marcos rebelo, scala-user

What if you just write x => x?


--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

marcos rebelo

unread,
Apr 16, 2017, 8:39:48 AM4/16/17
to Naftoli Gugenheim, scala-user
if I do:


  def withUploadStream[T, OS <: OutputStream](
                                               path: String,
                                               osCB: OutputStream => OS = os => os

                                             )(
                                               cb: OS => T
                                             )(
                                               implicit ec: ExecutionContext
                                             ): Future[T] = {

I get:

missing parameter type
[error]                                                osCB: OutputStream => OS = os => os
[error]                                                                           ^

and once again I need:

osCB: OutputStream => OS = {os: OutputStream => os}

Is there a better way?

Best
Marcos


To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+unsubscribe@googlegroups.com.

Viktor Klang

unread,
Apr 16, 2017, 9:06:12 AM4/16/17
to marcos rebelo, Naftoli Gugenheim, scala-user
OutputStream is more general than OS, you can't prove all OutputStreams are OSs (identity). (OS => OutputStream would work tho)

--
Cheers,
Reply all
Reply to author
Forward
0 new messages