fs2

why is my code not returning anything ? Scala fs2

99封情书 提交于 2021-01-07 01:28:15
问题 The program permits pushing Mapping Ints to Double and identifying the exit time from the queue. The program is not showing any error but It is not printing anything. What am I missing ? import cats.effect.{ExitCode, IO, IOApp, Timer} import fs2._ import fs2.concurrent.Queue import scala.concurrent.duration._ import scala.util.Random class Tst(q1: Queue[IO, (Double, IO[Long])])(implicit timer: Timer[IO]) { val streamData = Stream.emit(1) val scheduledStream = Stream.fixedDelay[IO](10.seconds)

why is my code not returning anything ? Scala fs2

末鹿安然 提交于 2021-01-07 01:26:49
问题 The program permits pushing Mapping Ints to Double and identifying the exit time from the queue. The program is not showing any error but It is not printing anything. What am I missing ? import cats.effect.{ExitCode, IO, IOApp, Timer} import fs2._ import fs2.concurrent.Queue import scala.concurrent.duration._ import scala.util.Random class Tst(q1: Queue[IO, (Double, IO[Long])])(implicit timer: Timer[IO]) { val streamData = Stream.emit(1) val scheduledStream = Stream.fixedDelay[IO](10.seconds)

How to group large stream into sub streams

五迷三道 提交于 2020-12-04 08:56:55
问题 I want to group large Stream[F, A] into Stream[Stream[F, A]] with at most n element for inner stream. This is what I did, basically pipe chunks into Queue[F, Queue[F, Chunk[A]] , and then yields queue elements as result stream. implicit class StreamSyntax[F[_], A](s: Stream[F, A])( implicit F: Concurrent[F]) { def groupedPipe( lastQRef: Ref[F, Queue[F, Option[Chunk[A]]]], n: Int): Pipe[F, A, Stream[F, A]] = { in => val initQs = Queue.unbounded[F, Option[Queue[F, Option[Chunk[A]]]]].flatMap {

How to group large stream into sub streams

自古美人都是妖i 提交于 2020-12-04 08:56:31
问题 I want to group large Stream[F, A] into Stream[Stream[F, A]] with at most n element for inner stream. This is what I did, basically pipe chunks into Queue[F, Queue[F, Chunk[A]] , and then yields queue elements as result stream. implicit class StreamSyntax[F[_], A](s: Stream[F, A])( implicit F: Concurrent[F]) { def groupedPipe( lastQRef: Ref[F, Queue[F, Option[Chunk[A]]]], n: Int): Pipe[F, A, Stream[F, A]] = { in => val initQs = Queue.unbounded[F, Option[Queue[F, Option[Chunk[A]]]]].flatMap {

C#中文件操作IO

末鹿安然 提交于 2020-03-03 16:00:15
StreamReader StreamReader sr = new StreamReader("qiufeng.txt", Encoding.GetEncoding("gb2312")); Console.WriteLine(sr.ReadLine()); Console.Wri /*--> */ /*--> */ teLine(sr.ReadLine()); 使用ReadLine()读取,每次读一行,并且每次读取的时候,从上次读取的下一行开始,并且,当文档读完的时候,返回空 string str2 = string.Empty; while ((str2 = sr.ReadLine()) != null) { Console.WriteLine(str2); } 读取文档的每一行。他和 string str3 = sr.ReadToEnd(); /*--> */ /*--> */ 是等价的。 WriteAllLines string[] str = { "山中相送罢,", "日暮掩柴扉。", "春草明年绿,", "王孙归不归。" }; File.WriteAllLines("qiufeng.txt", str); 会写入qiufeng.txt,并且如果原来文档中有数据会清空再增加 File.WriteAllText(@"D:\2.txt",sb.ToString()); /*-

FS2 Stream with StateT[IO, _, _], periodically dumping state

a 夏天 提交于 2020-03-02 10:52:23
问题 I have a program which consumes an infinite stream of data. Along the way I'd like to record some metrics, which form a monoid since they're just simple sums and averages. Periodically, I want to write out these metrics somewhere, clear them, and return to accumulating them. I have essentially: object Foo { type MetricsIO[A] = StateT[IO, MetricData, A] def recordMetric(m: MetricData): MetricsIO[Unit] = { StateT.modify(_.combine(m)) } def sendMetrics: MetricsIO[Unit] = { StateT.modifyF { s =>

Fs2 Stream.Compiler is not found (could not find implicit value Compiler[[x]F[x],G])

為{幸葍}努か 提交于 2020-02-24 03:56:47
问题 I am trying to compile the stream, but somehow Compiler is not in scope, what context bound is needed for bringing it in scope? import cats.Monad def compilingStream[F[_]: Monad]: F[List[Int]] = { val stream: fs2.Stream[F, Int] = fs2.Stream.emit(1).covary[F] stream.head.compile.toList } error: could not find implicit value for parameter compiler: fs2.Stream.Compiler[[x]F[x],G] stream.head.compile.toList ^ 回答1: Fs2 Stream#compile now requires a Sync[F] (see this): import cats.effect.Sync def

Mocking a method which returns an fs2.Stream

蓝咒 提交于 2019-12-10 18:06:01
问题 Why isn't it possible to mock a method that returns an fs2.Stream with a Mockito mock? Mockito is complaining that I am trying to return a FreeC instead of a Stream. Why is that and how can I get it working? The following code: import cats.effect.IO import fs2.Stream import org.mockito.Mockito.when import org.scalatest.FlatSpec import org.scalatest.mockito.MockitoSugar trait MyTrait { def method: Stream[IO, Int] } class TestSpec extends FlatSpec with MockitoSugar { val m: MyTrait = mock