Permalink
Browse files

Add Box.!== as an opposite to Box.===.

This literally inverts the Box.=== result, so Empty boxes will always
return true and Full Boxes will only return true if their values are NOT
EQUAL to the passed value.
  • Loading branch information...
1 parent 6d55cd3 commit 2ed0e401fa263b80943bd3ddd506f848a46cf57c @Shadowfiend Shadowfiend committed Jun 21, 2012
@@ -429,6 +429,12 @@ sealed abstract class Box[+A] extends Product {
def ===[B >: A](to: B): Boolean = false
/**
+ * Returns true if the value contained in this box is NOT equal to the
+ * specified value, or if this Box is Empty.
+ */
+ def !==[B >: A](to: B): Boolean = ! (this === to)
+
+ /**
* Equivalent to map(f).openOr(Full(dflt))
*/
def dmap[B](dflt: => B)(f: A => B): B = dflt
@@ -86,6 +86,18 @@ object BoxSpec extends Specification("Box Specification") with ScalaCheck with B
Full(1).choice(gotIt)(Full("nothing")) must_== Full("got it: 1")
Empty.choice(gotIt)(Full("nothing")) must_== Full("nothing")
}
+ "define an '===' method, returning true only if this box is Full and its value matches" in {
+ Full(1).===(1) must beTrue
+ Full(2).===(1) must beFalse
+ Empty.===(1) must beFalse
+ (Empty ?~ "failure").===(1) must beFalse
+ }
+ "define a '!==' method, returning true only if this box is Empty or its value does not match" in {
+ Full(1).!==(1) must beFalse
+ Full(2).!==(1) must beTrue
+ Empty.!==(1) must beTrue
+ (Empty ?~ "failure").!==(1) must beTrue
+ }
}
"A Full Box" should {

0 comments on commit 2ed0e40

Please sign in to comment.