Skip to content

Instantly share code, notes, and snippets.

@kiambogo
Created November 1, 2018 05:30
Show Gist options
  • Save kiambogo/29c60340531bae4b4fd96270cc8f99df to your computer and use it in GitHub Desktop.
Save kiambogo/29c60340531bae4b4fd96270cc8f99df to your computer and use it in GitHub Desktop.
circe-fs2 example
import cats.effect._
import scala.concurrent.ExecutionContext
import java.nio.file.Paths
import io.circe.generic.auto._
import io.circe.fs2._
implicit val ec: ExecutionContext = ExecutionContext.global
implicit val ioContextShift: ContextShift[IO] = IO.contextShift(ec)
case class Repo(repo: String, stars: Int)
val input = """[
{ "repo": "circe-fs2", "stars": 14 },
{ "repo": "circe-config", "stars": 5 }
]"""
fs2.Stream(input).covary[IO]
.flatMap{b => fs2.Stream.emits(b.getBytes)}
.through(byteArrayParser)
.through(decoder[IO, Repo])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment