def func(datalist, b=False):
    output = []
    for data in datalist:
        data_a = funcA(data)
        data_b = funcB(data_a) if b else data_a
        data_c = funcC(data_b) if data.c else data_b
        data_d = funcD(data_c)
        output.append(data_d)
    return output


def func_dom_simple(datalist, want_b=False):
    out = []
    for data in datalist:
        want_c = data.c
        data = funcA(data)
        if want_b:
            data = funcB(data)
        if want_c:
            data = funcC(data)
        data = funcD(data)
        out.append(data)
    return out


def compose(*functions):
    return lambda start: reduce(lambda f, x: f(x), functions, start)


def identity(x):
    return x


def func_very_haskell(datalist, want_b=False):
    return map(
        lambda data: compose(
            funcA,
            funcB if b else identity,
            funcC if data.c else identity,
            funcD,
        )(data),
        datalist,
    )


def func_very_haskell2(datalist, want_b=False):
    funcAB = compose(funcA, *([funcB] if b else []))
    return map(
        lambda data: compose(
            funcAB,
            funcC if data.c else identity,
            funcD,
        )(data),
        datalist,
    )
