This repository was archived by the owner on Aug 17, 2019. It is now read-only.
File tree 1 file changed +7
-1
lines changed
src/main/scala/com/ckkloverdos/maybe
1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -138,7 +138,9 @@ object MaybeOption {
138
138
/**
139
139
* A Maybe that can be either a Just or a Failed. So, this is like Scala's Either.
140
140
*/
141
- sealed trait MaybeEither [+ A ] extends Maybe [A ]
141
+ sealed trait MaybeEither [+ A ] extends Maybe [A ] {
142
+ def toEither : Either [Throwable , A ]
143
+ }
142
144
143
145
object MaybeEither {
144
146
def apply [A ](x : ⇒ A ): MaybeEither [A ] = Maybe (x) match {
@@ -181,6 +183,8 @@ final case class Just[+A](get: A) extends MaybeOption[A] with MaybeEither[A] {
181
183
def toList = List (get)
182
184
def toStream = Stream .cons(get, Stream .Empty )
183
185
186
+ def toEither : Either [Throwable , A ] = Right (get)
187
+
184
188
def isJust = true
185
189
def isFailed = false
186
190
def isNoVal = false
@@ -292,6 +296,8 @@ final case class Failed(exception: Throwable) extends MaybeEither[Nothing] {
292
296
def toList = Maybe .MaybeEmptyList
293
297
def toStream = Stream .Empty
294
298
299
+ def toEither : Either [Throwable , Nothing ] = Left (exception)
300
+
295
301
def getOr [B >: Nothing ](b : ⇒ B ) = b
296
302
297
303
def fold [T ](onJust : (Nothing ) ⇒ T )(onNoVal : ⇒ T )(onFailed : (Failed )⇒ T ) = onFailed(this )
You can’t perform that action at this time.
0 commit comments