
**Describe the unexpected behaviour**

Current implementation of arrayCompact does not behave as other higher-order functions: it accepts lambda function as its first argument, but then it compacts array returned by lambda, not original array (see below for example).

**How to reproduce**
* Which ClickHouse server version to use

Any modern

* Queries to run that lead to unexpected result

select arrayCompact(x -> x.2 , groupArray(tuple(number, intDiv(number, 3) % 3))) from numbers(10);

**Expected behavior**

arrayCompact shall follow normal higher-order functons way and use results of lambda function ([0,0,0,1,1,1,2,2,2,0]) to compact original array ([(0,0),(1,0),(2,0),(3,1),(4,1),(5,1),(6,2),(7,2),(8,2),(9,0)]) into [(0,0),(3,1),(6,2),(9,0)]

**Additional context**

Use case: timeseries (time, value) with lots of repeated values that shall be compacted into (first time, value) when value repeats.

{
        ColumnPtr res;
        mapped = mapped->convertToFullColumnIfConst();
        if (!(executeType< UInt8 >(mapped, array, res) ||
            executeType< UInt16>(mapped, array, res) ||
            executeType< UInt32>(mapped, array, res) ||
            executeType< UInt64>(mapped, array, res) ||
            executeType< Int8  >(mapped, array, res) ||
            executeType< Int16 >(mapped, array, res) ||
            executeType< Int32 >(mapped, array, res) ||
            executeType< Int64 >(mapped, array, res) ||
            executeType<Float32>(mapped, array, res) ||
            executeType<Float64>(mapped, array, res)) ||
            executeType<Decimal32>(mapped, array, res) ||
            executeType<Decimal64>(mapped, array, res) ||
            executeType<Decimal128>(mapped, array, res))
        {
            executeGeneric(mapped, array, res);
        }
        return res;
    }
};
struct NameArrayCompact { static constexpr auto name = "arrayCompact"; };
using FunctionArrayCompact = FunctionArrayMapped<ArrayCompactImpl, NameArrayCompact>;
void registerFunctionArrayCompact(FunctionFactory & factory)
{
    factory.registerFunction<FunctionArrayCompact>();
}
}