title: RxJava2 Maybe return empty Observable if no element
body: <p>Is there a better / more idiomatic way to use a <code>Maybe</code> type from JavaRx 2 than <code>flatMap</code> and <code>try/catch</code>? The following example takes a <code>Maybe&lt;User&gt;</code> and tries to book them a random ticket for a flight. If the user doesn't exist, return an empty <code>Observable</code>.</p>
  
  <pre><code>fun bookRandomTicketFor(userId: UUID): Observable&lt;Ticket&gt; {
      val agencies = travelAgents() // Observable&lt;TravelAgency&gt;
      val user = findById(userId) // Maybe&lt;User&gt;
      val location = locate() // Observable&lt;GeoLocation&gt;
  
      return Observable
              .just(user.toObservable())
              .flatMap { usr -&gt;
                  try {
                      usr.zipWith(location, { aUser, location -&gt;
                          agencies
                                  .flatMap { agency -&gt;
                                      agency
                                              .search(aUser, location) // Observable&lt;Flight&gt;.
                                              .toList() // Convert to List&lt;Flight&gt;.
                                              .toObservable() // And to Observable&lt;List&lt;Flight&gt;&gt;.
                                              .flatMap { flights -&gt; // So it can be shuffled,
                                                  Observable.just( // giving a random order.
                                                          shuffle(flights as MutableList&lt;Flight&gt;)[0]
                                                  )
                                              }
                                  }.firstElement() // Now take the first randomly shuffled Flight.
                      }).flatMap { flight -&gt;
                          book(user.toObservable(), flight.toObservable())
                      }
                  } catch (ex: Exception) {
                      Observable.empty&lt;Ticket&gt;()
                  }
              }
              .doOnSubscribe { Logger.log("Random ticket: start for $userId") }
              .doOnComplete { Logger.log("Random ticket: exit for $userId") }
  }
  </code></pre>
  
  <p>It seems a bit of a fudge to have to convert the <code>Maybe&lt;User&gt;</code> to an <code>Observable</code> and start with an <code>Observable&lt;Observable&lt;User&gt;&gt;</code> that I can then <code>flatMap</code> and <code>try/catch</code>. Just wondering if there is a neater approach to doing this?</p>