Пример #1
0
    def visit_Select_of_SelectMany(self, parent, selection):
        r'''
        seq.SelectMany(x: f(x)).Select(y: g(y))
        => Select(SelectMany(seq, x: f(x)), y: g(y))
        is turned into
        seq.SelectMany(x: f(x).Select(y: g(y)))
        => SelectMany(seq, x: Select(f(x), y: g(y)))
        '''
        func_g = selection
        func_f = parent.selection

        return self.visit(
            SelectMany(
                parent.source,
                lambda_body_replace(func_f,
                                    make_Select(lambda_body(func_f), func_g))))
Пример #2
0
    def visit_Where_of_SelectMany(self, parent, filter):
        '''
        seq.SelectMany(x: f(x)).Where(y: g(y))
        => Where(SelectMany(seq, x: f(x)), y: g(y))
        Is turned into:
        seq.SelectMany(x: f(x).Where(y: g(y)))
        => SelectMany(seq, x: Where(f(x), g(y)))
        '''
        func_f = parent.selection
        func_g = filter
        seq = parent.source

        return self.visit(
            SelectMany(
                seq,
                lambda_body_replace(func_f, Where(lambda_body(func_f),
                                                  func_g))))
Пример #3
0
    def visit_SelectMany_of_SelectMany(self, parent, selection):
        '''
        Transformation #1:
        seq.SelectMany(x: f(x)).SelectMany(y: f(y))
        => SelectMany(SelectMany(seq, x: f(x)), y: f(y))
        is turned into:
        seq.SelectMany(x: f(x).SelectMany(y: f(y)))
        => SelectMany(seq, x: SelectMany(f(x), y: f(y)))
        '''
        #TODO: Get to the point we can actually test that this works correctly
        raise BaseException('untested')
        func_g = selection
        func_f = parent.selection

        return self.visit(
            SelectMany(
                parent.source,
                lambda_body_replace(func_f,
                                    SelectMany(lambda_body(func_f), func_g))))
def test_lambda_replace_simple_unwrapped():
    t = lambda_unwrap(ast.parse("lambda b: b+1"))
    b = ast.parse("2*b").body[0].value
    expected = lambda_unwrap(ast.parse("lambda b: 2*b"))

    assert ast.dump(expected) == ast.dump(lambda_body_replace(t, b))
def test_lambda_replace_simple():
    t = ast.parse("lambda b: b+1")
    b = ast.parse("2*b").body[0].value
    expected = ast.parse("lambda b: 2*b")

    assert ast.dump(expected) == ast.dump(lambda_body_replace(t, b))