示例#1
0
    def test_head(self):
        self.assertEqual(0, iters.head([0, 1, 2]))
        self.assertEqual(None, iters.head([]))

        def gen():
            yield 1
            yield 2
            yield 3

        self.assertEqual(1, iters.head(gen()))
示例#2
0
文件: tests.py 项目: Gizmo707/fn.py
    def test_head(self):
        self.assertEqual(0, iters.head([0,1,2]))
        self.assertEqual(None, iters.head([]))

        def gen():
            yield 1 
            yield 2
            yield 3 

        self.assertEqual(1, iters.head(gen()))
示例#3
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)
示例#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)
示例#5
0
async def get_optional_product_with_id(product_id):
    return Option.from_value(head(filter(_['id'] == product_id, products)))
示例#6
0
 def inner(self):
     return head(filter(bool, map(fn, self.comments.all())))
示例#7
0
def is_variable(var):
    """
    Is the string a variable reference?
    """
    return isinstance(var, basestring) and it.head(var) == ':'
示例#8
0
def has_doc_dict(qc_node):
    return isinstance(it.head(qc_node), dict)