示例#1
0
 def _walk_node(n):
     if has_doc_dict(n):
         return _walk_node(list(it.tail(n)))
     else:
         operator = it.head(n)
         rest = it.tail(n)
         return [operator] + f(rest)
示例#2
0
    def test_tail(self):
        self.assertEqual([1, 2], list(iters.tail([0, 1, 2])))
        self.assertEqual([], list(iters.tail([])))

        def gen():
            yield 1
            yield 2
            yield 3

        self.assertEqual([2, 3], list(iters.tail(gen())))
示例#3
0
文件: tests.py 项目: Gizmo707/fn.py
    def test_tail(self):
        self.assertEqual([1,2], list(iters.tail([0,1,2])))
        self.assertEqual([], list(iters.tail([])))

        def gen():
            yield 1 
            yield 2
            yield 3 

        self.assertEqual([2,3], list(iters.tail(gen())))
示例#4
0
def eval(node):
    """
    Evaluate an s-expression by applying the operator to the rest of the arguments.

    Args:
      node (list): An s-expression list in the form of [operator, arg1, arg2, ...]

    Yields:
      The result of "applying" the operator to the arugments. Will evaluate
      recursively if any of the args are a list.

    Examples:
      >>> eval([>, 0, 1])
      FALSE
    """
    if isinstance(it.head(node), dict):
        return eval(list(it.tail(node)))
    else:
        args = map(fn.recursive_apply(eval), it.tail(node))
        f = operator(it.head(node))
        return apply(f, args)