Skip to content
This repository was archived by the owner on Aug 17, 2019. It is now read-only.

Commit 1aa7b3c

Browse files
committed
Remove more API
1 parent 07840c3 commit 1aa7b3c

File tree

3 files changed

+1
-115
lines changed

3 files changed

+1
-115
lines changed

src/main/scala/com/ckkloverdos/manifest/ManifestHelpers.scala

-62
This file was deleted.

src/main/scala/com/ckkloverdos/maybe/Maybe.scala

+1-23
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package com.ckkloverdos.maybe
1818

19-
import com.ckkloverdos.manifest.ManifestHelpers
20-
import collection.{Iterator}
19+
import collection.Iterator
2120

2221
/**
2322
* Inspired by Lift's `Box`, Haskell's `Maybe` and Scala's `Option`.
@@ -82,8 +81,6 @@ sealed abstract class Maybe[+A] extends Serializable {
8281
final def foldJust[T](onJust: (A) T)(onOther: T): T =
8382
fold(onJust)(onOther)(f onOther)
8483

85-
def castTo[B : Manifest]: Maybe[B]
86-
8784
/**
8885
* Flattens two successive maybes to one.
8986
*/
@@ -206,21 +203,6 @@ final case class Just[+A](get: A) extends MaybeOption[A] with MaybeEither[A] {
206203
}
207204
def foreach[U](f: A U) = f(get)
208205

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-
224206
def flatten1[U](implicit ev: A <:< Maybe[U]): Maybe[U] = ev(get)
225207

226208
def throwMe = throw new Exception(toString)
@@ -261,8 +243,6 @@ case object NoVal extends MaybeOption[Nothing] {
261243

262244
def finallyFlatMap[B](_finally: (Nothing) Unit)(f: (Nothing) Maybe[B]) = this
263245

264-
def castTo[B : Manifest] = this
265-
266246
def flatten1[U](implicit ev: <:<[Nothing, Maybe[U]]) = this
267247

268248
def throwMe = throw new Exception(toString)
@@ -312,8 +292,6 @@ final case class Failed(exception: Throwable) extends MaybeEither[Nothing] {
312292

313293
def finallyFlatMap[B](_finally: (Nothing) Unit)(f: (Nothing) Maybe[B]) = this
314294

315-
def castTo[B : Manifest] = this
316-
317295
def flatten1[U](implicit ev: <:<[Nothing, Maybe[U]]) = this
318296

319297
def throwMe = throw exception

src/test/scala/com/ckkloverdos/maybe/MaybeTest.scala

-30
Original file line numberDiff line numberDiff line change
@@ -93,36 +93,6 @@ class MaybeTest {
9393
Assert.assertEquals(Maybe("foo"), Maybe(Maybe("foo")).flatten1)
9494
}
9595

96-
@Test
97-
def testCastNullToNoVal: Unit = {
98-
Assert.assertEquals(NoVal, Just(null).castTo[String])
99-
}
100-
101-
@Test
102-
def testCastToCharSequenceSuccess: Unit = {
103-
val help = "Help"
104-
val aJust: Maybe[_] = Just(help)
105-
Assert.assertTrue(aJust.castTo[CharSequence].isJust)
106-
}
107-
108-
@Test
109-
def testCastToScalaObjectFailure: Unit = {
110-
val help = "Help"
111-
val aJust: Maybe[_] = Just(help)
112-
Assert.assertTrue(aJust.castTo[ScalaObject].isFailed)
113-
}
114-
115-
@Test
116-
def testCastToIntFailure: Unit = {
117-
Assert.assertTrue(Just(1).castTo[String].isFailed)
118-
}
119-
120-
@Test
121-
def testCastToIntSuccess: Unit = {
122-
val cast = Maybe(1).castTo[Int]
123-
Assert.assertTrue(cast.isJust)
124-
}
125-
12696
@Test
12797
def testFinallyMap: Unit = {
12898
var _flag1 = false

0 commit comments

Comments
 (0)