Skip to content

Instantly share code, notes, and snippets.

@windymelt
Created April 19, 2024 18:13
Show Gist options
  • Save windymelt/44592c52eddd5c87a0faf389c6280716 to your computer and use it in GitHub Desktop.
Save windymelt/44592c52eddd5c87a0faf389c6280716 to your computer and use it in GitHub Desktop.
import cats.effect.kernel.Resource
import cats.effect.IO
import cats.data.EitherT
trait Client {
def get(uri: String): IO[String]
}
val client: Resource[IO, Client] = Resource.pure(new {
def get(uri: String): IO[String] = IO.pure("result")
})
def parseUri(str: String): Either[String, String] = Right("http://example.com/")
def call(): EitherT[IO, String, String] = EitherT(client.use { c =>
(for
uri <- EitherT.fromEither[IO](parseUri("http://foo.example.com/"))
res <- EitherT.right[String](c.get(uri))
yield res).value
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment