Created
March 25, 2022 22:24
-
-
Save keirlawson/0a08db3cd515c9850f300a2dd1646c05 to your computer and use it in GitHub Desktop.
JSON test file from Scalacheck Arbitrary/Circe Encoder
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
def streamGen[A](gen: Gen[A]): Stream[IO, A] = Stream.repeatEval(IO(gen.sample)).flatMap(Stream.fromOption(_)) | |
def generateTestFile[A : Arbitrary : Encoder](file: fs2.io.file.Path, items: Long): IO[Unit] = { | |
val values = streamGen(Arbitrary.arbitrary[A]) | |
val jsons = values.map(Encoder[A].apply).take(items) | |
val lines = Stream("[\n") ++ jsons.map(_.toString()).intersperse(",\n") ++ Stream("]") | |
lines | |
.through(text.utf8.encode) | |
.through(Files[IO].writeAll(file)) | |
.compile | |
.drain | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment