Created
November 1, 2018 05:30
-
-
Save kiambogo/29c60340531bae4b4fd96270cc8f99df to your computer and use it in GitHub Desktop.
circe-fs2 example
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._ | |
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