my_func(fcn1::Function, passedIn::Float64) =
my_func(fcn1, (y, z, passedin)->default_fcn(0.0, y, z, passedin),
passedIn)
You could achieve the same effect in one definition if you put fcn2 as a
keyword argument. Also check out FastAnonymous.jl if performance matters.
On Monday, January 18, 2016 at 4:25:20 PM UTC-5, Christopher Alexander
wrote:
>
> Thanks for the response! As a follow-up, what would I do in a situation
> where the passed-in second function (fcn2) and the default function take a
> different number of arguments?
>
> Thanks!
>
> Chris
>
> On Monday, January 18, 2016 at 4:06:41 PM UTC-5, Erik Schnetter wrote:
>>
>> 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/
>>
>