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