Exponentiation operator for iterated functions?

Interesting generalization… It’s basically providing a shorter reduce syntax for the case where the collection is a repetition of the same element. Then I would rather provide nice syntax for the collection itself:

julia> ↑(el,n::Integer) = fill(el,n)

julia> reduce(*, 2↑10)
1024

julia> typeof(1.0) |> ∘(supertype↑3...)
Number

We could also define a reciprocal operator for the reduction:

↓(itr, op::Function) = reduce(op, itr)

julia> (2↑10)↓*
1024

julia> typeof(1.0) |> (supertype↑3)↓∘
Number

But the definition of should probably define the associativity of reduction (using foldl or foldr), and it’s not clear which it should be.

In any case I think @Tamas_Papp is right, it’s better to define this in a package using another operator.

2 Likes