Questions tagged [fs2]

FS2: Functional Streams for Scala

FS2: Functional Streams for Scala - is a streaming I/O library. The design goals are compositionality, expressiveness, resource safety, and speed.

149 questions
5
votes
1 answer

Skip errors in the infinite Stream

I have an infinite fs2.Stream which may encounter errors. I'd like to skip those errors with doing nothing (probably log) and keep streaming further elements. Example: //An example val stream = fs2.Stream .awakeEvery[IO](1.second) .evalMap(_…
Some Name
  • 8,555
  • 5
  • 27
  • 77
5
votes
1 answer

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

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] =…
Mikhail Golubtsov
  • 6,285
  • 3
  • 29
  • 36
5
votes
2 answers

How to convert a Stream[IO, List[A]] to Stream[IO, A]

I want to parse a json file which output a collection of A. The signature of the Output is IO[List[A]] How can I convert this value to a Stream: Stream[IO, A] ? I can convert to a Stream[IO, List[A]] but it is not what I…
nam
  • 3,542
  • 9
  • 46
  • 68
5
votes
1 answer

How to implement a recursive Fibonacci sequence in Scala using FS2?

While trying to become familiar with FS2, I came across a nifty recursive implementation using the Scala collections' Stream, and thought I'd have a go at trying it in FS2: import fs2.{Pure, Stream} val fibs: Stream[Pure, Int] = Stream[Pure,…
bbarker
  • 11,636
  • 9
  • 38
  • 62
4
votes
2 answers

is "implictly" in scala now deprecated or at least not required anymore?

checking into fs2 tutorial, I stumbled upon the following code def client[F[_]: MonadCancelThrow: Console: Network]: F[Unit] = Network[F].client(SocketAddress(host"localhost", port"5555")).use { socket => socket.write(Chunk.array("Hello,…
MaatDeamon
  • 9,532
  • 9
  • 60
  • 127
4
votes
1 answer

Building a ZIO and http4s app, works with sbt, fails with Bazel: missing an implicit

I'm attempting to build a service that integrates ZIO and http4s. The starting point is this example (it uses zio 1.0.1, http4s 0.21.3, scala 2.12.11) I was able to build the code below without any problems using sbt, but am running into trouble…
Shastick
  • 1,218
  • 1
  • 12
  • 29
4
votes
1 answer

Model multiple function calls with a stream (in a safe, FP way)

Given a function A => IO[B] (aka Kleisli[IO, A, B]) that is meant to be called multiple times, and has side effects, like updating a DB, how to delegate such multiple calls of it into a stream (I guess Pipe[IO, A, B]) (fs2, monix…
V-Lamp
  • 1,630
  • 10
  • 18
4
votes
2 answers

FS2: is it possible to complete Queue gracefully?

Suppose that I want to convert some legacy asynchronous API into FS2 Streams. The API provides an interface with 3 callbacks: next element, success, error. I'd like the Stream to emit all the elements and then complete upon receiving success or…
Paul Lysak
  • 1,284
  • 1
  • 14
  • 18
4
votes
1 answer

remove the filtered line from the file using scala fs2 file streaming

how to remove the filtered lines from the current streaming file using fs2 and get the count of filtered lines as the return type? ex: If the old.txt contains strings separated by a newline (\n): john sam chen yval .... and val myList =…
vkt
  • 1,401
  • 2
  • 20
  • 46
4
votes
1 answer

Processing multipart content in http4s

I would like to know how can I process multipart content using the http4s library. Imagine a service with the following snippet (the complete gist is here): case GET -> Root / "form" => Ok( """| | |
Labra
  • 1,412
  • 1
  • 13
  • 33
3
votes
2 answers

Converting a stream of coproduct to a stream of HList - Shapeless and FS2

I have a fs2 Stream Stream[F, C] where C <: Coproduct. And I want to transform it into a Stream[F, H] where H <: HList. This HList should contain all members that the coproduct C had. So, essentially, a Pipe[F, C, H] . The fs2 Pipe will work by…
eitaporra
  • 51
  • 7
3
votes
1 answer

How to terminate FS2 stream started from SBT Shell?

If I run this program from SBT shell, then cancel it, it will keep printing "hello". I have to exit SBT to make it stop. Why is that? import cats.effect.{ExitCode, IO, IOApp} import fs2.Stream import scala.concurrent.duration._ object FS2 extends…
Cpt. Senkfuss
  • 1,347
  • 3
  • 12
  • 20
3
votes
1 answer

Process Stream with inner stream with fs2

I have 2 csv files with sorted data: File 1: numbers sorted (~1GB) File 2: numbers sorted + extra data (~20GB) I need to lookup all numbers from file 1 in file 2 and do some processing (numbers in file 2 that are not present in file 1 are…
Vitor Mota
  • 255
  • 2
  • 13
3
votes
2 answers

How to asynchronously interrupt an fs2 stream?

I'm trying to interrupt an fs2 stream with SignalRef. I set up and run the stream with the following. The stream should run when switch contains false and should interrupt when switch contains true import cats.effect.IO import fs2.Stream …
mdornfe1
  • 1,982
  • 1
  • 24
  • 42
3
votes
1 answer

Changing effect type of fs2.Stream

I'm using doobie which can produce an fs2.Stream[ConnectionIO, Int] of database rows (Int in my case). The ConnectionIO[A] is doobie's internal type. Given a HKT F[_] and val nt: ConnectionIO ~> F is there a way to get fs2.Stream[F, Int] from…
Some Name
  • 8,555
  • 5
  • 27
  • 77
1
2
3
9 10