# How to select specific functionality in general pipeline

**URL:** https://discourse.julialang.org/t/how-to-select-specific-functionality-in-general-pipeline/53184
**Category:** New to Julia
**Created:** [January 12, 2021, 1:38am UTC](https://discourse.julialang.org/t/how-to-select-specific-functionality-in-general-pipeline/53184 "2021-01-12T01:38:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)
#### Post date: [January 12, 2021, 1:38am UTC](https://discourse.julialang.org/t/how-to-select-specific-functionality-in-general-pipeline/53184/1 "2021-01-12T01:38:57Z")

</div>

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:

```julia
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?

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [January 12, 2021, 2:57am UTC](https://discourse.julialang.org/t/how-to-select-specific-functionality-in-general-pipeline/53184/2 "2021-01-12T02:57:00Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)
#### Post date: [January 12, 2021, 4:23am UTC](https://discourse.julialang.org/t/how-to-select-specific-functionality-in-general-pipeline/53184/3 "2021-01-12T04:23:03Z")

</div>

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.
