예제 #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)