Define the second function like this: ``` my_func(fcn1::Function, passedIn::Float64) = my_func(fcn1, default_fcn, passedIn) ```
-erik On Mon, Jan 18, 2016 at 4:02 PM, Christopher Alexander <[email protected]> wrote: > Hello all, I had a question concerning a best practice in a particular case > of multiple dispatch which is as follows. > > Let's say I have a function with two different methods. > > function my_func(fcn1::Function,fcn2::Function, passedIn::Float64) > x = 0.0 > y = 1.0 > z = 2.0 > val1 = fcn(x, y, passedIn) > val2 = fcn2(y, z, passedIn) > return val1, val2 > end > > function my_func(fcn1::Function, passedIn::Float64) > x = 0.0 > y = 1.0 > z = 2.0 > val1 = fcn(x, y, passedIn) > val2 = default_fcn(x, y, z, passedIn) > return val1, val2 > end > > My question is basically, what would be the best way to do this without > massive code duplication? The actual situation I am working with has much > more going on in the function, so it's not like I could create some init > function to set up x, y, & z. But literally the only different behavior > between the two methods is whether or not a second function is passed in. > > Thanks! > > Chris > -- Erik Schnetter <[email protected]> http://www.perimeterinstitute.ca/personal/eschnetter/
