Created
April 19, 2024 18:13
-
-
Save windymelt/44592c52eddd5c87a0faf389c6280716 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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