@@ -144,7 +144,11 @@ object Maybe {
144
144
case _ ⇒ Just (value)
145
145
}
146
146
} catch {
147
- case e : Throwable ⇒ Failed (e)
147
+ case e : Error ⇒
148
+ throw e
149
+
150
+ case e : Throwable ⇒
151
+ Failed (e)
148
152
}
149
153
}
150
154
}
@@ -166,7 +170,13 @@ final case class Just[+A](get: A) extends MaybeOption[A] with MaybeEither[A] {
166
170
167
171
def mapJust [B >: A ](f : (Just [A ]) => Maybe [B ]) = {
168
172
try f(this )
169
- catch { case e : Exception ⇒ Failed (e) }
173
+ catch {
174
+ case e : Error ⇒
175
+ throw e
176
+
177
+ case e : Throwable ⇒
178
+ Failed (e)
179
+ }
170
180
}
171
181
172
182
def mapNoVal [B >: A ](f : => Maybe [B ]) = this
@@ -188,17 +198,27 @@ final case class Just[+A](get: A) extends MaybeOption[A] with MaybeEither[A] {
188
198
def || [B >: A ](f : ⇒ Maybe [B ]) = this
189
199
190
200
def map [B ](f : (A ) ⇒ B )= Maybe (f(get))
201
+
191
202
def flatMap [B ](f : (A ) ⇒ Maybe [B ]) = {
192
203
try f(get)
193
204
catch {
194
- case t : Throwable ⇒ Failed (t)
205
+ case e : Error ⇒
206
+ throw e
207
+
208
+ case e : Throwable ⇒
209
+ Failed (e)
195
210
}
196
211
}
212
+
197
213
def filter (f : (A ) ⇒ Boolean ): Maybe [A ] = {
198
214
try {
199
215
if (f(get)) this else NoVal
200
216
} catch {
201
- case t : Throwable ⇒ Failed (t)
217
+ case e : Error ⇒
218
+ throw e
219
+
220
+ case e : Throwable ⇒
221
+ Failed (e)
202
222
}
203
223
}
204
224
def foreach [U ](f : A ⇒ U ) = f(get)
@@ -276,7 +296,13 @@ final case class Failed(exception: Throwable) extends MaybeEither[Nothing] {
276
296
277
297
def mapFailed [B >: Nothing ](f : (Failed ) => Maybe [B ]) = {
278
298
try f(this )
279
- catch { case e : Exception ⇒ Failed (e) }
299
+ catch {
300
+ case e : Error ⇒
301
+ throw e
302
+
303
+ case e : Throwable ⇒
304
+ Failed (e)
305
+ }
280
306
}
281
307
282
308
def fold [T ](onJust : (Nothing ) ⇒ T )(onNoVal : ⇒ T )(onFailed : (Failed )⇒ T ) = onFailed(this )
@@ -298,8 +324,9 @@ final case class Failed(exception: Throwable) extends MaybeEither[Nothing] {
298
324
299
325
override def equals (that : Any ) = {
300
326
that match {
301
- case failed : Failed ⇒
302
- this .exception == failed.exception
327
+ case Failed (exception) ⇒
328
+ this .exception == exception
329
+
303
330
case _ ⇒
304
331
false
305
332
}
0 commit comments