Beispiel #1
0
    def test_nothing_monad_law_associativity(self):
        # (m >>= f) >>= g is just like doing m >>= (\x -> f x >>= g)
        m = Nothing()
        f = lambda x: unit(x + 1000)
        g = lambda y: unit(y * 42)

        self.assertEqual(m.bind(f).bind(g), m.bind(lambda x: f(x).bind(g)))
Beispiel #2
0
    def test_nothing_monad_law_associativity(self):
        # (m >>= f) >>= g is just like doing m >>= (\x -> f x >>= g)
        m = Nothing()
        f = lambda x: unit(x+1000)
        g = lambda y: unit(y*42)

        self.assertEqual(
            m.bind(f).bind(g),
            m.bind(lambda x: f(x).bind(g))
        )
Beispiel #3
0
    def test_nothing_monad_bind(self):
        m = Nothing()
        f = lambda x: unit(x*10)

        self.assertEqual(
            m.bind(f),
            Nothing()
        )
Beispiel #4
0
    def test_nothing_monad_bind(self):
        m = Nothing()
        f = lambda x: unit(x*10)

        self.assertEqual(
            m.bind(f),
            Nothing()
        )
Beispiel #5
0
    def test_nothing_monad_law_right_identity(self):
        # m >>= return is no different than just m.

        m = Nothing()

        self.assertEqual(
            m.bind(unit),
            m
        )
Beispiel #6
0
    def test_nothing_monad_law_right_identity(self):
        # m >>= return is no different than just m.

        m = Nothing()

        self.assertEqual(
            m.bind(unit),
            m
        )