title: Composing Multiple Futures and Option in Scala with ZIO
body: <p>I just started evaluating ZIO to improve the programming model and the performance of my asynchronous Scala code. In my code base I deal with <code>Future[Option[T]]</code> often, and to this point I have dealt with that using Scalaz's <code>OptionT</code> monad transformer. Now I want to try this with ZIO.</p>
  
  <p>Consider two functions:</p>
  
  <p><code>def foo: String =&gt; Future[Option[T]]</code>
  and
  <code>def bar: T =&gt; Future[U]</code></p>
  
  <p>I tried something like this:</p>
  
  <pre><code>val t = for {
         o: Option[Int] &lt;- ZIO.fromFuture { implicit ec =&gt;
              foo("test")
         }
         i: Int &lt;- ZIO.fromOption(o)
         s: String &lt;- ZIO.fromFuture { implicit ec =&gt;
              bar(i)
         }
  } yield s
  </code></pre>
  
  <p>According to my IDE, <code>t</code> is of type <code>ZIO[Any, Any, String]</code> in this scenario. I don't know what to do with that.</p>
  
  <p>I want to consider three possibilities:</p>
  
  <ul>
  <li>The "success" case where <code>foo</code> produces a <code>Some</code> that can be composed with other functions on the value</li>
  <li>The case where <code>foo</code> produces a <code>None</code></li>
  <li>The case where either function produces an error</li>
  </ul>
  
  <p>I am not sure how to parse those possibilities in this scenario with ZIO. Any help is appreciated.</p>