Hello,
Is there a way to use zip() or enumerate() within the IF statement?
I’m looking for a safter way to run the code below. I’ve created structs to dispatch an appropriate model based off a “category” in a dataframe. Currently it’s only dispatching the custom models correctly because custom_cats and custom_cats_structs are aligned (that is when looping through category: Custom 1, Struct: custom_a is the appropriate choice).
It seems like doing something like zip(custom_cats, custom_cats_structs) would be safer / more preferred way, but I can’t seem to figure out what the right syntax is.
Here’s what I have (which works, but again seems suboptimal):
struct general end
struct custom_a end
struct custom_b end
df = DataFrame(category=["Normal 1", "Normal 2", "Normal 3", "Custom 1", "Custom 2"], X=[5, 4, 8, 9,10], Y =[1000,5000,3000,1200,5000])
cats = ["Normal 1", "Normal 2", "Normal 3", "Custom 1", "Custom 2"]
normal_cats = ["Normal 1", "Normal 2", "Normal 3"]
custom_cats = ["Custom 1", "Custom 2"]
custom_cats_structs = [custom_a(),custom_b()]
function mymodel(x::general)
println("Genearl Model Hello")
end
function mymodel(x::custom_a)
println("This is my first custom model")
end
function mymodel(x::custom_b)
println("This is my second custom model")
end
function run_models(cats,norm,cust,cust_structs)
for c in cats
println("working on $c")
if c in norm
mymodel(general())
elseif c in cust
n = 1
mymodel(cust_structs[n])
n+1
end
end
end
run_models(cats,normal_cats,custom_cats,custom_cats_structs)
Hope this makes sense. Thanks for your help.