Questions tagged [zio]

ZIO is a zero-dependency Scala library for asynchronous and concurrent programming with similar features as Cats IO or Monix.

ZIO — A type-safe, zero-dependency library for asynchronous and concurrent programming in Scala.

Homepage: https://zio.dev/

241 questions
2
votes
2 answers

Output value of type A as result

I have next code in IDEA (scala workshop), import zio.console.Console import zio.{IO, Task, ZIO} val st :Seq[Task[Int]] = Seq(Task(1),Task(2),Task(3)) val t : Task[List[Int]]= IO.collectAll(st) val r : ZIO[Console, Throwable, List[Int]] =…
Aleksey N Yakushev
  • 443
  • 1
  • 3
  • 11
2
votes
2 answers

Initial delay for ZIO ZSchedule

The schedule I'm trying to make would have to: Start after a specified delay Repeat at a fixed rate Terminate if it reaches given time limit or encounters terminating state So what I have is (2.) and (3.): val repeatUntilTimeLimitReached = …
energi
  • 79
  • 8
2
votes
2 answers

Purpose of pattern where object extends trait of the same name - object Live extends Live

I am trying ZIO. I do not understand why Live is added as Trait, and then an object is provided, like: object Live extends Live This pattern is found in different places, for example zio.console.Console. Is there a reason, or are there cases where…
pme
  • 14,156
  • 3
  • 52
  • 95
2
votes
1 answer

The difference between IO and UIO in scalaz ZIO

What is the difference between IO and UIO in the new version from ZIO for example UIO[Long] and IO[Nothing, Long]?
NaseemMahasneh
  • 485
  • 5
  • 19
1
vote
1 answer

How to get a simple string encoding for Enumeratum enum in Zio-JSON

So lets say I have a simple enumeratum based enum. import enumeratum._ sealed trait Fruit extends EnumEntry object Fruit extends Enum[Fruit] { override val values: IndexedSeq[Fruit] = findValues case object Avocado extends Fruit …
Peter Lamberg
  • 8,151
  • 3
  • 55
  • 69
1
vote
1 answer

sttp/tapir - testing endpoint with JSON body

I have some tapir endpoints defined as part of a zio-http server. Everything works for real, including those POST endpoints with JSON bodies. However, I've been unable to get a unit test using SttpBackendStub & TapirStubInterpreter to work for…
1
vote
0 answers

Scala, ZIO, Sttp, Circe - how to map error response to custom trait in sttp client using circe?

I have a simple sttp client implementation: basicRequest.auth .get(...) .response(asJsonEither[GeneralTrait, MyResponse]) .send(backend) .map(_.body.left.map { case HttpError(body, statusCode) =>…
Developus
  • 1,400
  • 2
  • 14
  • 50
1
vote
1 answer

How to create ZStream of String from ZStream of Byte

I need to read file from http. I'm using sttp with ZioBackend like this: val sttpBackend: SttpBackend[Task, ZioStreams] = ??? val request = basicRequest .post(uri"...") .response(asStreamUnsafe(ZioStreams)) …
Izbassar Tolegen
  • 1,990
  • 2
  • 20
  • 37
1
vote
1 answer

ZioHttp end point - Return json response

I am creating a ZioHttp Rest endpoint... For a Json request I want to return Json response ... I'm able to retrun logs, print lines but not sure how to return json response... Here's my code: import zio.{Console, _} import zhttp._ import…
1
vote
1 answer

Scala, Tapir, ZIO - add metrics interceptor with default error handler

Have a question regarding Prometheus metrics in Tapir and ZIO. I have a simple code: val metrics = PrometheusMetrics.default[Task]() val options: ZioHttpServerOptions[Any] = ZioHttpServerOptions .customiseInterceptors …
Developus
  • 1,400
  • 2
  • 14
  • 50
1
vote
1 answer

Scala, ZIO - convert Future[Either[...]] into ZIO

I have a simple method which returns Future[Either[Throwable, MyValue]]. Now I would like to convert it to ZIO. I created: def zioMethod(): ZIO[Any, Throwable, MyValue] = ZIO.fromFuture {implicit ec => futureEitherMethod().flatMap {…
Developus
  • 1,400
  • 2
  • 14
  • 50
1
vote
0 answers

How did parameterizing this function make my Zio project stop working?

I've started writing a server that uses zio-http to forward messages from a Pulsar topic to a WebSocket. It was working fine, but I realized I was creating the consumer again when the socket was being closed, so I refactored that code to accept the…
Isvara
  • 3,403
  • 1
  • 28
  • 42
1
vote
0 answers

How do I stream different partitions in parallel in ZIO Kafka

I have a Kafka architecture program and want to stream different partitions in parallel on each consumer instance, do I use the mapNPar or should I create different consumer instances and then fork them and join them in a for flat map?
khalilkm01
  • 25
  • 4
1
vote
1 answer

What happened to Accessible[XYZ] in Zio 2?

What happened to Accessible[XYZ] in Zio 2? Used and mentioned by Kit here: https://youtu.be/yXcqjQ7Kcwk?t=681 What are the recommended new patterns?
Chris W.
  • 2,266
  • 20
  • 40
1
vote
3 answers

Is it possible to control the number of argument in a function when using varargs in compile time(Scala)?

Let us suppose, we have to create the OddList[+T] which contains only odd number of elements. Now can we do something like this OddList(1,2) //Works fine OddList(1,2,3) //Compilation error if there is no condition of odd/even then we would simply…
Pranjut
  • 1,747
  • 5
  • 18
  • 31