Setting up a Function Chain with Single Allocation

First of all, it’s worth asking what the real goal here is. Giving a name to a quantity doesn’t cause any more allocation than not naming it. So if your code is working as-is, you might not need to worry at all.

That said, you might find the (\circ) function composition operator useful:

julia> f = x -> filter(iseven, x)
#13 (generic function with 1 method)

julia> f = f ∘ (x -> filter(isodd, x))
var"#13#14"() ∘ var"#15#16"()

julia> f([1,2,3,4])
Int64[]
1 Like