# How to best program this function with cases?

**URL:** <https://discourse.julialang.org/t/how-to-best-program-this-function-with-cases/68703>\
**Category:** General Usage\
**Tags:** componentarrays\
**Created:** [September 24, 2021, 3:03pm UTC](https://discourse.julialang.org/t/how-to-best-program-this-function-with-cases/68703 "2021-09-24T15:03:21Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [September 25, 2021, 1:36am UTC](https://discourse.julialang.org/t/how-to-best-program-this-function-with-cases/68703/6 "2021-09-25T01:36:04Z")

</div>

I use it for separating components of complex models. For example:

> [@Parsimonious way to unpack big structs](https://discourse.julialang.org/t/parsimonious-way-to-unpack-big-structs/66522/9):
>
> using your example, it would be using ComponentArrays using UnPack p = ComponentArray(α=0.1, β=0.2, γ=0.3) function f2(x; p=p) @unpack α, β, γ = p return x^(α) + x^(β) + x^(γ) end I also like to organize the parameters inside the ComponentArray, for example: using ComponentArrays using UnPack # full model function model(p; data=data) @unpack p1, p2 = p @unpack data1, data2 = data # component 1 r1 = f1(p1; data=data1) # component 2 r2 = f2(p2; data=data…

---

_[View the full topic](https://discourse.julialang.org/t/how-to-best-program-this-function-with-cases/68703)._
