Hello,
I’m currently writing a PDE solver in julia, and I’m wrapping the inputs in a structure in order. Among these inputs is the initial condition V0 and can be either a constant or a function.

My question is, what is the best way to write a structure with such field? I currently have the following implemented:

struct input{T,P<:AbstractFloat,O<:Signed}
V0 :: T
L :: P
N :: O
end

Is this the correct approach to this use case? In this situation, the field input.V0 is always well defined:

Ok, so declaring the structure for the function case and then create a method to it to deal with the constant case, right? What did you mean about avoiding special cases? Sorry, I didn’t understand!

By the way, what means Input(_->V0,...)? It’s a kind of mapping or something?

Right, so that you don’t need to write separate codes for V0::Number and V0::Function and just assume that V0 is always a function in the code that uses the structure.

_->V0 is an anonymous function of one argument which returns V0 for any input. You may write it as x->V0 or function(x) V0 end. The underscore just shows that the argument is in fact ignored. More verbosely, the same constructor is written as

function Input(V0::Number, L, N)
function always_V0(x)
return V0
end
return Input(always_V0, float(L), Signed(N))
end