def test_list_applicative_law_identity(self): # pure id <*> v = v # Singleton list x = unit(42) self.assertEquals(pure(identity).apply(x), x) # Empty list y = List.empty() self.assertEquals(pure(identity).apply(y), y) # Log list y = List.from_iterable(range(42)) self.assertEquals(pure(identity).apply(y), y)
def _get_setup_args(path): rtn = List.empty() with open(path, 'rU') as file: t = compile(file.read(), path, 'exec', ast.PyCF_ONLY_AST) for node in (n for n in t.body if isinstance(n, ast.Expr)): if isinstance(node.value, ast.Call): if hasattr(node.value.func, 'id') and node.value.func.id == 'setup': rtn = List.from_iterable(node.value.keywords) break else: print(dir(node.value.func), node.value.func.value) return rtn
def test_list_functor_law2(self): # fmap (f . g) x = fmap f (fmap g x) def f(x): return x + 10 def g(x): return x * 10 # Singleton list x = unit(42) self.assertEquals(x.map(compose(f, g)), x.map(g).map(f)) # Empty list y = List.empty() self.assertEquals(y.map(compose(f, g)), y.map(g).map(f)) # Long list z = List.from_iterable(range(42)) self.assertEquals(z.map(compose(f, g)), z.map(g).map(f))
def test_list_applicative_empty_func(self): v = unit(42) w = List.from_iterable([1, 2, 3]) self.assertEquals(List.empty().apply(v).apply(w), List(Unit))