Cats-effect: Add a function on Resource that turns it into an `F ~> F`

Created on 19 Oct 2020  路  6Comments  路  Source: typelevel/cats-effect

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) }
}
CE 3 good first issue

All 6 comments

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 :)

Was this page helpful?
0 / 5 - 0 ratings