# Wrapper type of static array, how to expose iterator

**URL:** <https://discourse.julialang.org/t/wrapper-type-of-static-array-how-to-expose-iterator/118124>\
**Category:** General Usage\
**Tags:** parametric-types, staticarrays\
**Created:** [August 13, 2024, 8:41am UTC](https://discourse.julialang.org/t/wrapper-type-of-static-array-how-to-expose-iterator/118124 "2024-08-13T08:41:39Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![NatMath](https://avatars.discourse-cdn.com/v4/letter/n/4491bb/32.png) [@NatMath](https://discourse.julialang.org/u/NatMath)\
**Post date:** [August 13, 2024, 2:03pm UTC](https://discourse.julialang.org/t/wrapper-type-of-static-array-how-to-expose-iterator/118124/4 "2024-08-13T14:03:07Z")

</div>

Here’s my working solution for anyone stumbling here. Based on [this other discourse post](https://discourse.julialang.org/t/custom-broadcasting-for-static-immutable-type/69426). The main issue I had is the documentation doesn’t describe how to implement broadcasting for immutable types, such as when the backing vector is a `SVector`.

```julia
struct Point{N, T<:Number} <: AbstractArray{T, 1}
    p::SVector{N, T}
end; export Point

# Broadcasting
import Base.broadcastable
Base.broadcastable(point::Point) = point
struct PointStyle{N} <: Broadcast.BroadcastStyle end
import Base.Broadcast.BroadcastStyle 
Base.Broadcast.BroadcastStyle(::Type{Point{N,T}}) where {N,T} = PointStyle{N}()
Base.Broadcast.BroadcastStyle(::PointStyle{N}, ::Broadcast.DefaultArrayStyle{0}) where N = PointStyle{N}()
import Base.Broadcast.materialize
function Base.Broadcast.materialize(B::Broadcast.Broadcasted{PointStyle{N}}) where N
    flat = Broadcast.flatten(B)
    args = flat.args
    f = flat.f
    ps = map(x -> x isa Point ? x.p : Ref(x), args)
    Point(f.(ps...))
end

```

---

_[View the full topic](https://discourse.julialang.org/t/wrapper-type-of-static-array-how-to-expose-iterator/118124)._
