コード例 #1
0
ファイル: test_maybe.py プロジェクト: yuhangwang/OSlash
    def test_just_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 = Just(42)

        self.assertEquals(x.map(compose(f, g)), x.map(g).map(f))
コード例 #2
0
ファイル: test_maybe.py プロジェクト: cbenz/OSlash
    def test_just_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 = Just(42)

        self.assertEquals(
            x.map(compose(f, g)),
            x.map(g).map(f)
        )
コード例 #3
0
ファイル: test_maybe.py プロジェクト: cbenz/OSlash
 def test_just_functor_law1(self):
     # fmap id = id
     x = Just(3)
     self.assertEquals(
         x.map(identity),
         x
     )
コード例 #4
0
ファイル: test_maybe.py プロジェクト: stjordanis/OSlash
 def test_just_functor_law1(self):
     # fmap id = id
     x = Just(3)
     self.assertEqual(
         x.map(identity),
         x
     )
コード例 #5
0
ファイル: test_maybe.py プロジェクト: cbenz/OSlash
    def test_just_functor_map(self):
        f = lambda x: x*2
        x = Just(21)

        self.assertEquals(
            x.map(f),
            Just(42)
        )
コード例 #6
0
ファイル: test_maybe.py プロジェクト: stjordanis/OSlash
    def test_just_functor_map(self):
        f = lambda x: x * 2
        x = Just(21)

        self.assertEqual(
            x.map(f),
            Just(42)
        )