예제 #1
0
    def test_with_right(self):
        match = Match(Either.right("python"))

        @match.when(Right)
        def case_right(v):
            return v + " is right!"

        @match.when(Left)
        def case_left(v):
            self.fail("case_left should not called")

        self.assertEqual(match.end, "python is right!")
예제 #2
0
    def test_with_left(self):
        match = Match(Either.left("not python"))

        @match.when(Right)
        def case_right(v):
            self.fail("case_right should not called")

        @match.when(Left)
        def case_left(v):
            return "left because " + v

        self.assertEqual(match.end, "left because not python")
예제 #3
0
 def test_basic(self):
     self.assertEqual(Either.right('hachi') >> lambd.title(), u'Hachi')
     self.assertEqual(list(map(lambd + 2, range(3))), [2, 3, 4])