Add support for Rx2 Maybe. (#45)

Add support for Rx2 Maybe
diff --git a/reactive/kotlinx-coroutines-rx2/src/test/kotlin/kotlinx/coroutines/experimental/rx2/ConvertTest.kt b/reactive/kotlinx-coroutines-rx2/src/test/kotlin/kotlinx/coroutines/experimental/rx2/ConvertTest.kt
index c22ef77..7649391 100644
--- a/reactive/kotlinx-coroutines-rx2/src/test/kotlin/kotlinx/coroutines/experimental/rx2/ConvertTest.kt
+++ b/reactive/kotlinx-coroutines-rx2/src/test/kotlin/kotlinx/coroutines/experimental/rx2/ConvertTest.kt
@@ -19,6 +19,7 @@
 import kotlinx.coroutines.experimental.*
 import kotlinx.coroutines.experimental.channels.produce
 import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNull
 import org.junit.Test
 
 class ConvertTest : TestBase() {
@@ -56,6 +57,50 @@
     }
 
     @Test
+    fun testToMaybe() {
+        val d = async(CommonPool) {
+            delay(50)
+            "OK"
+        }
+        val maybe1 = d.asMaybe(Unconfined)
+        checkMaybeValue(maybe1) {
+            assertEquals("OK", it)
+        }
+        val maybe2 = d.asMaybe(Unconfined)
+        checkMaybeValue(maybe2) {
+            assertEquals("OK", it)
+        }
+    }
+
+    @Test
+    fun testToMaybeEmpty() {
+        val d = async(CommonPool) {
+            delay(50)
+            null
+        }
+        val maybe1 = d.asMaybe(Unconfined)
+        checkMaybeValue(maybe1, ::assertNull)
+        val maybe2 = d.asMaybe(Unconfined)
+        checkMaybeValue(maybe2, ::assertNull)
+    }
+
+    @Test
+    fun testToMaybeFail() {
+        val d = async(CommonPool) {
+            delay(50)
+            throw TestException("OK")
+        }
+        val maybe1 = d.asMaybe(Unconfined)
+        checkErroneous(maybe1) {
+            check(it is TestException && it.message == "OK") { "$it" }
+        }
+        val maybe2 = d.asMaybe(Unconfined)
+        checkErroneous(maybe2) {
+            check(it is TestException && it.message == "OK") { "$it" }
+        }
+    }
+
+    @Test
     fun testToSingle() {
         val d = async(CommonPool) {
             delay(50)