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)))
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)) )
def test_nothing_monad_bind(self): m = Nothing() f = lambda x: unit(x*10) self.assertEqual( m.bind(f), Nothing() )
def test_nothing_monad_bind(self): m = Nothing() f = lambda x: unit(x*10) self.assertEqual( m.bind(f), Nothing() )
def test_nothing_monad_law_right_identity(self): # m >>= return is no different than just m. m = Nothing() self.assertEqual( m.bind(unit), m )
def test_nothing_monad_law_right_identity(self): # m >>= return is no different than just m. m = Nothing() self.assertEqual( m.bind(unit), m )