Developus
Developus

Reputation: 1462

How to return empty Vector as a result of Task?

I have created a simple project and one of the method is (it is ZIO Task

type Task[+A] = ZIO[Any, Throwable, A]):

def findSmth(..) : Task[Either[Exception, Vector[SomeData]]] 

I would like to return an empty Vector in some cases. I tried to do it this way:

ZIO.fromFuture { implicit ctx =>
   Future.successful(Right(Seq.empty[SomeData].toVector))
}

or

ZIO.fromFuture { implicit ctx =>
   Future.successful(Right(Vector.empty))
}

But it always return None instead of empty vector (empty list). How should I refactor this code to return just an empty result (vector with no data inside), without exceptions or Nones?

Upvotes: 0

Views: 673

Answers (1)

Martijn
Martijn

Reputation: 12102

using the apply method on the Task object,

Task(Right(Vector.empty))

Upvotes: 2

Related Questions