How to select specific functionality in general pipeline

Hi,

I have several pipelines which have mostly the same behavior with a few differences, and I’m trying to understand the tradeoffs between them. Most of my use cases look something like this:

function do_stuff(pipeline)
  if pipeline == pipeline1
    specific_start = specific_start1
  elseif pipeline == pipeline2
    specific_start = specific_start2
  end

  return ThreadsX.map(values, specific_end \circ do_common_stuff \circ specific_start)
end

There are a lot of ways to organize these specific bits, such as multiple dispatch using singleton types, if-else statements as above, if-else statements within a general “specific_start” function, or using a Dict. My question is, what’s considered a best practice here? For example, in Haskell I might use pattern matching, while in an object-oriented language specific_start would be a method of pipeline. Is there one approach that’s preferred or significantly faster in Julia?

It really depends on what kind of difference there is between pipeline1 and pipeline2. For instance, one may have different “types” of error calculation, and the user may want to extend it when using your package – this calls for making a struct AbstractPipeline and using multi-dispatch.

If however, different pipelines are just different in “values”, (an example is in the closed=:left or :right in StatsBase) you can use if-else, or if you feel fancy, use a package that mimics the trait behavior in Haskell (to achieve dispatch by value).

1 Like

Thanks! They’re definitely just values in my case, so it sounds like if-else statements or maybe something like MLStyle is the way to go.