# Collecting into either \`StaticArray\` or \`Array\`

**URL:** https://discourse.julialang.org/t/collecting-into-either-staticarray-or-array/128669
**Category:** General Usage
**Tags:** staticarrays
**Created:** [May 3, 2025, 4:50pm UTC](https://discourse.julialang.org/t/collecting-into-either-staticarray-or-array/128669 "2025-05-03T16:50:43Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![circonflexe](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@circonflexe](https://discourse.julialang.org/u/circonflexe)
#### Post date: [May 3, 2025, 4:50pm UTC](https://discourse.julialang.org/t/collecting-into-either-staticarray-or-array/128669/1 "2025-05-03T16:50:43Z")

</div>

I might have missed something in `StaticArrays.jl`. Is there an agreed type which can contain the length/multidimensional size of an iterator, either statically or dynamically, and which can be used to collect into either a plain `Array` or a `StaticArray`? I could write something like this:

```julia
struct StaticCollector{N,D} end # D is a `Tuple` of static dimensions
struct DynamicCollector{N}
  dims::NTuple{N,Int}
end

Base.collect(::StaticCollector{N,D}, itr) =
   StaticArrays.sacollect(StaticArray{N,D}, #= etc...=#)
Base.collect(::DynamicCollector, itr) = collect(itr)

```

but this particular wheel has likely already been invented (and my implementation would of course be much worse than any existing one). Did I miss something?
