Created
July 29, 2017 14:09
-
-
Save BenFradet/a69e3fa86ad2654ed017e2cb2881c307 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
lazy val fs2Version = "0.9.7" | |
lazy val circeVersion = "0.8.0" | |
lazy val root = (project in file(".")) | |
.settings( | |
name := "circe-fs2-example", | |
scalaVersion := "2.12.3", | |
libraryDependencies ++= | |
"co.fs2" %% "fs2-io" % fs2Version +: Seq( | |
"io.circe" %% "circe-generic", | |
"io.circe" %% "circe-fs2" | |
).map(_ % circeVersion) | |
) |
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 _root_.fs2.{io, text, Task, Stream} | |
import _root_.io.circe.Json | |
import _root_.io.circe.fs2._ | |
import _root_.io.circe.generic.auto._ | |
import java.nio.file.Paths | |
object Main { | |
case class Popularity(repo: String, stars: Int) | |
def main(args: Array[String]): Unit = { | |
val stringStream: Stream[Task, String] = | |
io.file.readAll[Task](Paths.get("popularity.json"), 4096) | |
.through(text.utf8Decode) | |
val parsedStream: Stream[Task, Json] = | |
stringStream.through(stringParser) | |
val popularityStream: Stream[Task, Popularity] = | |
parsedStream.through(decoder[Task, Popularity]) | |
println(popularityStream.runLog.unsafeAttemptRun()) | |
} | |
} |
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
[ | |
{ | |
"repo": "circe-fs2", | |
"stars": 13 | |
}, | |
{ | |
"repo": "circe-yaml", | |
"stars": 32 | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment