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
3
votes
1 answer

zio, custom Assertion renderer for current value

We have a custom zio.test.Assertion that wrap json-path-assert: def isJson(matching: org.hamcrest.Matcher[_ >: ReadContext]): Assertion[HttpEntity] = { def test(entity: => HttpEntity): Boolean = { // Removed for brevity } …
gervais.b
  • 2,294
  • 2
  • 22
  • 46
3
votes
1 answer

ZIO Streams: Which is the difference between a ZSink and a ZTransducer?

I'm studying ZIO Streams, using version 1.0.9 of the library zio-streams. I cannot find any reference that shows me the difference between a ZSink and a ZTransducer. What is the difference?
riccardo.cardin
  • 7,971
  • 5
  • 57
  • 106
3
votes
1 answer

Is there a simple way to convert Option[Task[T]] to Task[Option[T]]?

While using monix.eval.Task or zio.Task, is there a simple way to convert Option of Task to Task of Option?
3
votes
0 answers

Scala, ZIO - how to convert Unit into ZIO[Any, Nothing, Unit] after iterating all elements in list?

I have a simple method: def process(element: SomeData): ZIO[Any, Nothing, Unit] I would like to use it on every element from list: def processElements(list: List[SomeData]): ZIO[Any, Nothing, Unit] = { list.foreach(element => …
Developus
  • 1,400
  • 2
  • 14
  • 50
3
votes
1 answer

Scala, ZIO - how to convert ZIO to Task and get result?

I have a method which returns some ZIO: def method(...): ZIO[Any with clock, SomeError, Unit] The method which calls this return Task[Unit]: def otherMethod(..): Task[Unit] = { ZIO.effect(method(...)) } The problem is when I call it with…
Developus
  • 1,400
  • 2
  • 14
  • 50
3
votes
3 answers

Zio, transform Seq[ZIO] to ZIO[Seq]

That may be a dumb question, but starting with ZIO, I cannot manage to convert a Seq[ZIO] to ZIO[Seq]: def translate(keys: Seq[String], locales: Seq[Locale]):RIO[Translator, Seq[Translation]] = { for { service <- ZIO.environment[Translator] …
gervais.b
  • 2,294
  • 2
  • 22
  • 46
3
votes
1 answer

Fiber on the JVM with Scala IO implementations

My understanding is that IO Implementation like cats-effetcs or Zio use fibers, and this on the JVM. I wonder what's the underlying lib or framework they are using, if the JVM e.g. 11 does not officially support fibers yet ?
MaatDeamon
  • 9,532
  • 9
  • 60
  • 127
3
votes
2 answers

Scala, ZIO - convert Future into ZIO or ZIO into Future. Is it possible?

I created two versions of my service. First one uses Futures, other one uses ZIO as an effect. I have a simple method which use Future as a result effect: def get(id: String)(implicit executionContext: ExecutionContext): Future[Data] I also has…
Developus
  • 1,400
  • 2
  • 14
  • 50
3
votes
3 answers

Abort early in a fold with ZIO

I wanted to add an answer to abort-early-in-a-fold for ZIO. So I took the solution with cats: cats solution def sumEvenNumbers(nums: Stream[Int]): Option[Long] = { import cats.implicits._ nums.foldM(0L) { case (acc, c) if c % 2 == 0 =>…
pme
  • 14,156
  • 3
  • 52
  • 95
3
votes
1 answer

How to handle an ADT (sealed trait) with ZIO config

How can I add a Configuration Description manually for an Algebraic Data Type with ZIO Conf. In the examples I found an example on how to handle ADTs with Magnolia. Is this also possible when adding manually a Description of the…
pme
  • 14,156
  • 3
  • 52
  • 95
3
votes
1 answer

Running http4s server with ZIO Env

Trying to learn using ZIO library, so I decided to create a basic web service app. Idea pretty basic, use http4s lib for server and route endpoints, print "hello world" on endpoint call. With the help of docs and examples I found, produces…
Bublik
  • 912
  • 5
  • 15
  • 30
3
votes
1 answer

ZIO: Why I get 'An unchecked error was produced.'

I have a misunderstanding with exception handling in ZIO. I followed the ZIO-Documentation. In a test class I run the following code: new DefaultRuntime {}.unsafeRun( (for { peopleRef <- Ref.make(Vector(People())) _ <-…
pme
  • 14,156
  • 3
  • 52
  • 95
3
votes
1 answer

Scala ZIO Ref datatype

I have one class in Scala with four parameters 2 of them is variable and I wanted to use the Ref data type in Zio to control the access to those variable here is my code : import zio._ class Rectangle(val width: Int,val height: Int) { val x:…
NaseemMahasneh
  • 485
  • 5
  • 19
3
votes
2 answers

How do I make a Scalaz ZIO lazy?

I have a heavy side-effecting function (think database call) that I want to use as a lazy value, so that it gets called only on first use (and not at all if never used). How do I do this with ZIO? If my program looks like this, the function gets…
Thilo
  • 257,207
  • 101
  • 511
  • 656
2
votes
0 answers

Equivalent looking ZIO future interop code with different results

Working with ZIO for the first time and wrote some code that boiled down to val x = ZStream.fromIterable(Iterable.empty).runDrain await(zio.Runtime.default.unsafeRun(x.toFuture)) it compiles but fails at runtime with [info] …
Sign
  • 1,919
  • 18
  • 33
1 2
3
16 17