I'm trying to use symulacrum
's @typeclass
to avoid writing Ops/Syntax boilerplate. I have a trait parameterized with effect and a type:
@typeclass trait Close[F[_], T]{
def close(t: T): F[Unit]
}
With the intention to be used as follows:
trait Stream[F[_], Pipe]{
def open(): F[Pipe]
def drain(): F[Unit]
}
object App{
def runApp[F[_], Pipe: Close[F, ?]](implicit stream: Stream[F, Pipe]) = {
for{
pipe <- stream.open()
_ <- stream.drain(pipe)
_ <- pipe.close()
} yield ()
}
}
The reason I decided to put Close[F[_], T]
away was that some Pipe
s in my application are inherently unclosable so it is kind of wierd to put
close method for all Pipe
s
This is the error I get:
Error:(32, 4) @typeclass may only be applied to types that take a single type parameter
@typeclass trait Close[F[_], T]
QUESTION: In case of a trait
has multiple type parameters (like Close[F[_], T]
) do I have to write all the Ops/Syntax boilerplate on my own and symulacrum's @typeclass
cannot help here?