I'm trying to implement a function that I simplified as follows:
struct DummyStruct
x::Int64
y::Int64
z::Int64
end
function match_data_from_dummy_struct(dummy_struct::Vector{DummyStruct}, value::Int64)
# Long processing that includes:
# If called from match_data_x, match value with dummy_struct.x
# If called from match_data_y, match value with dummy_struct.y
# If called from match_data_z, match value with dummy_struct.z
end
function match_data_x()
# Call to match_data_from_dummy_struct
end
function match_data_y()
# Call to match_data_from_dummy_struct
end
function match_data_z()
# Call to match_data_from_dummy_struct
end
The ugly way to do this is to have three versions of the same match_data_from_dummy_struct:
match_data_from_dummy_struct_x: to match with DummyStruct.xmatch_data_from_dummy_struct_y: to match with DummyStruct.ymatch_data_from_dummy_struct_z: to match with DummyStruct.z
Another option is to pass a numeric value to match_data_from_dummy_struct, say if it's 1 then only match with x, if it's 2 then only match with y, if it's 3 then only match with z.
Is there a more clever / readable way to implement this?