|
16 | 16 |
|
17 | 17 | package com.ckkloverdos.maybe
|
18 | 18 |
|
19 |
| -import com.ckkloverdos.manifest.ManifestHelpers |
20 |
| -import collection.{Iterator} |
| 19 | +import collection.Iterator |
21 | 20 |
|
22 | 21 | /**
|
23 | 22 | * Inspired by Lift's `Box`, Haskell's `Maybe` and Scala's `Option`.
|
@@ -82,8 +81,6 @@ sealed abstract class Maybe[+A] extends Serializable {
|
82 | 81 | final def foldJust[T](onJust: (A) ⇒ T)(onOther: ⇒ T): T =
|
83 | 82 | fold(onJust)(onOther)(f ⇒ onOther)
|
84 | 83 |
|
85 |
| - def castTo[B : Manifest]: Maybe[B] |
86 |
| - |
87 | 84 | /**
|
88 | 85 | * Flattens two successive maybes to one.
|
89 | 86 | */
|
@@ -206,21 +203,6 @@ final case class Just[+A](get: A) extends MaybeOption[A] with MaybeEither[A] {
|
206 | 203 | }
|
207 | 204 | def foreach[U](f: A ⇒ U) = f(get)
|
208 | 205 |
|
209 |
| - def castTo[B : Manifest] = get match { |
210 |
| - case null ⇒ |
211 |
| - NoVal |
212 |
| - case value ⇒ //if(manifest[B].erasure.isInstance(value)) ⇒ this.asInstanceOf[Maybe[B]] |
213 |
| - val ma = ManifestHelpers.manifestOfAny(get) |
214 |
| - val mb = manifest[B] |
215 |
| - if(mb == ma || mb.erasure.isInstance(get)) |
216 |
| - this.asInstanceOf[Maybe[B]] |
217 |
| - else |
218 |
| - Failed( |
219 |
| - new ClassCastException("%s -> %s".format( |
220 |
| - get.asInstanceOf[AnyRef].getClass.getName, |
221 |
| - manifest[B].erasure.getName))) |
222 |
| - } |
223 |
| - |
224 | 206 | def flatten1[U](implicit ev: A <:< Maybe[U]): Maybe[U] = ev(get)
|
225 | 207 |
|
226 | 208 | def throwMe = throw new Exception(toString)
|
@@ -261,8 +243,6 @@ case object NoVal extends MaybeOption[Nothing] {
|
261 | 243 |
|
262 | 244 | def finallyFlatMap[B](_finally: (Nothing) ⇒ Unit)(f: (Nothing) ⇒ Maybe[B]) = this
|
263 | 245 |
|
264 |
| - def castTo[B : Manifest] = this |
265 |
| - |
266 | 246 | def flatten1[U](implicit ev: <:<[Nothing, Maybe[U]]) = this
|
267 | 247 |
|
268 | 248 | def throwMe = throw new Exception(toString)
|
@@ -312,8 +292,6 @@ final case class Failed(exception: Throwable) extends MaybeEither[Nothing] {
|
312 | 292 |
|
313 | 293 | def finallyFlatMap[B](_finally: (Nothing) ⇒ Unit)(f: (Nothing) ⇒ Maybe[B]) = this
|
314 | 294 |
|
315 |
| - def castTo[B : Manifest] = this |
316 |
| - |
317 | 295 | def flatten1[U](implicit ev: <:<[Nothing, Maybe[U]]) = this
|
318 | 296 |
|
319 | 297 | def throwMe = throw exception
|
|
0 commit comments