I think I’ve seen somewhere that closures being anonymous structs is an implementation detail which it is not recommended to depend on. Of course, if it is a single purpose project then by all means, just go ahead and implement that functor in there and use it while it works.
# Too lazy to load Flux, I think something like this might work except closurefunctor shall be Flux.functor
julia> function test(a, b)
return function(x)
return a .+ b .* x
end
end
test (generic function with 2 methods)
julia> tt = test(1, [2,3]);
julia> fieldnames(typeof(tt))
(:a, :b)
julia> closurefunctor(x) = map(fn -> getfield(x, fn), fieldnames(typeof(x))), test
closurefunctor (generic function with 1 method)
julia> p,re = closurefunctor(tt);
julia> p
(1, [2, 3])
julia> re(4, [1,2,3])
#21 (generic function with 1 method)
julia> ttt = re(4, [1,2,3])
#21 (generic function with 1 method)
julia> ttt(3)
3-element Array{Int64,1}:
7
10
13
Shameless plug: This package supports a static computation graph format designed to be created and manipulated programatically: GitHub - DrChainsaw/NaiveNASflux.jl: Your local Flux surgeon