Bridge the gap, please! (from Matlab to Julia)

two options:

# regular struct
julia> struct A{F,T}
         f::F
         x::Vector{T}
       end

julia> f(x) = sum(x)
f (generic function with 1 method)

julia> a = A(f,[1,2])
A{typeof(f), Int64}(f, [1, 2])

julia> a.f(a.x)
3

#or a callable struct

julia> struct B{T}
         x::Vector{T}
       end

julia> (b::B)() = sum(b.x)

julia> b = B([1,2])
B{Int64}([1, 2])

julia> b()
3




1 Like