Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ianj-als/pypeline.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Johnson <ian.johnson@appliedlanguage.com>2013-04-29 18:16:41 +0400
committerIan Johnson <ian.johnson@appliedlanguage.com>2013-04-29 18:16:41 +0400
commit81dbc44e6d7f6227de66224269aa63046c2e719b (patch)
treeaf8aaa6de512c57d2f580b2ed5774f5cb43b2abb
parent8ca8954d3cbfac0227740c6005f98e3c2cdfdb65 (diff)
Added __ne__ methods to appropriate types.
-rw-r--r--src/pypeline/core/types/either.py6
-rw-r--r--src/pypeline/core/types/just.py3
-rw-r--r--src/pypeline/core/types/nothing.py6
-rw-r--r--src/pypeline/core/types/tests/either_tests.py4
-rw-r--r--src/pypeline/core/types/tests/just_tests.py10
-rw-r--r--src/pypeline/core/types/tests/nothing_tests.py9
6 files changed, 32 insertions, 6 deletions
diff --git a/src/pypeline/core/types/either.py b/src/pypeline/core/types/either.py
index 5b650be..73dd6a6 100644
--- a/src/pypeline/core/types/either.py
+++ b/src/pypeline/core/types/either.py
@@ -36,6 +36,9 @@ class Left(Either):
return False
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
def __repr__(self):
return "<Left: %s>" % self.val
@@ -55,5 +58,8 @@ class Right(Either):
return False
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
def __repr__(self):
return "<Right: %s>" % self.val
diff --git a/src/pypeline/core/types/just.py b/src/pypeline/core/types/just.py
index 6328c5b..07d3c23 100644
--- a/src/pypeline/core/types/just.py
+++ b/src/pypeline/core/types/just.py
@@ -51,6 +51,9 @@ class Just(Maybe):
return True
return False
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
def __hash__(self):
return self._a.__hash__()
diff --git a/src/pypeline/core/types/nothing.py b/src/pypeline/core/types/nothing.py
index aab5df2..9d6e7e2 100644
--- a/src/pypeline/core/types/nothing.py
+++ b/src/pypeline/core/types/nothing.py
@@ -33,6 +33,12 @@ class Nothing(Maybe):
def return_(self, a):
return return_(a)
+ def __eq__(self, other):
+ return Nothing._instance is other
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
def __ge__(self, function):
return Nothing()
diff --git a/src/pypeline/core/types/tests/either_tests.py b/src/pypeline/core/types/tests/either_tests.py
index 74b762a..8f59f91 100644
--- a/src/pypeline/core/types/tests/either_tests.py
+++ b/src/pypeline/core/types/tests/either_tests.py
@@ -25,4 +25,8 @@ class EitherUnitTests(unittest.TestCase):
def test_eq(self):
self.assertEquals(Left(10), Left(10))
self.assertEquals(Right("something"), Right("something"))
+
+
+ def test_ne(self):
+ self.assertNotEquals(Left(10), Left(11))
self.assertNotEquals(Left(10), Right(10))
diff --git a/src/pypeline/core/types/tests/just_tests.py b/src/pypeline/core/types/tests/just_tests.py
index 8d0cf89..0c73b82 100644
--- a/src/pypeline/core/types/tests/just_tests.py
+++ b/src/pypeline/core/types/tests/just_tests.py
@@ -40,6 +40,10 @@ class JustMonadUnitTest(unittest.TestCase):
def test_eq(self):
- self.assertTrue(Just(10) == return_(10))
- self.assertFalse(Just(10) == None)
- self.assertFalse(Just(10) == object())
+ self.assertEquals(Just(10), return_(10))
+
+
+ def test_ne(self):
+ self.assertNotEquals(Just(11), return_(10))
+ self.assertNotEquals(Just(11), None)
+ self.assertNotEquals(Just(11), object())
diff --git a/src/pypeline/core/types/tests/nothing_tests.py b/src/pypeline/core/types/tests/nothing_tests.py
index a350379..ddda8d6 100644
--- a/src/pypeline/core/types/tests/nothing_tests.py
+++ b/src/pypeline/core/types/tests/nothing_tests.py
@@ -36,6 +36,9 @@ class NothingMonadUnitTest(unittest.TestCase):
def test_eq(self):
- self.assertTrue(Nothing() == return_("blah"))
- self.assertFalse(Nothing() == None)
- self.assertFalse(Nothing() == object())
+ self.assertEquals(Nothing(), return_("blah"))
+
+
+ def test_ne(self):
+ self.assertNotEquals(Nothing(), None)
+ self.assertNotEquals(Nothing(), object())