It would make the resource wrap an effect in an usage, ignoring the value produced by the resource.
Possible signature:
trait Resource[+F[_], +A] { self =>
//...
//some constraint might be required on G
def surround[G[x] >: F[x]]: G ~> G = new (G ~> G) { def apply[A](ga: G[A]): G[A] = self.use(_ => ga) }
}
I like the idea but I think that specific signature is cumbersome to use, i.e
surround[IO].apply(IO(1))
vs
surround(IO(1))
I wonder if .surround.apply(IO(1)) would just work...
How about having .surround just take the thing to be surrounded (surroundee?) directly as an argument, and have .surroundK to return a FunctionK?
Sounds good to me, that way should be even more ergonomic :)
Is it okay if I give this task a try?
@pkowalcze Go to town :)