Beispiel #1
0
    def test_nothing_functor_law2(self):
        # fmap (f . g) x = fmap f (fmap g x)
        def f(x):
            return x + 10

        def g(x):
            return x * 10

        x = Nothing()

        self.assertEquals(x.map(compose(f, g)), x.map(g).map(f))
Beispiel #2
0
    def test_nothing_functor_law2(self):
        # fmap (f . g) x = fmap f (fmap g x)
        def f(x):
            return x+10

        def g(x):
            return x*10

        x = Nothing()

        self.assertEquals(
            x.map(compose(f, g)),
            x.map(g).map(f)
        )
Beispiel #3
0
    def test_nothing_functor_map(self):
        f = lambda x: x+2
        x = Nothing()

        self.assertEquals(
            x.map(f),
            x
        )
Beispiel #4
0
    def test_nothing_functor_map(self):
        f = lambda x: x + 2
        x = Nothing()

        self.assertEqual(
            x.map(f),
            x
        )
Beispiel #5
0
    def test_nothing_applicative_law_functor(self):
        # pure f <*> x = fmap f x
        x = Nothing()
        f = lambda x: x * 42

        self.assertEquals(
            pure(f).apply(x),
            x.map(f)
        )
Beispiel #6
0
    def test_nothing_applicative_law_functor(self):
        # pure f <*> x = fmap f x
        x = Nothing()
        f = lambda x: x * 42

        self.assertEqual(
            pure(f).apply(x),
            x.map(f)
        )