# Is it possible to broadcast the property of a structure?

**URL:** https://discourse.julialang.org/t/is-it-possible-to-broadcast-the-property-of-a-structure/78615
**Category:** General Usage
**Tags:** broadcast, struct
**Created:** [March 28, 2022, 1:25pm UTC](https://discourse.julialang.org/t/is-it-possible-to-broadcast-the-property-of-a-structure/78615 "2022-03-28T13:25:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [March 28, 2022, 1:25pm UTC](https://discourse.julialang.org/t/is-it-possible-to-broadcast-the-property-of-a-structure/78615/1 "2022-03-28T13:25:37Z")

</div>

Often I need to “broadcast” the field of a given structure, e.g.:

```julia
struct Foo
    id::Int64
end
mylist = [Foo(1),Foo(2),Foo(1)]
[e.id for e in mylist]

```

There is no way to broadcast the dot indicating field ownership, e.g. `mylist..id` ? 🙂

---

<div class="post-metadata">

### Author: ![sbuercklin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbuercklin/32/15728_2.png) [@sbuercklin](https://discourse.julialang.org/u/sbuercklin)
#### Post date: [March 28, 2022, 1:30pm UTC](https://discourse.julialang.org/t/is-it-possible-to-broadcast-the-property-of-a-structure/78615/2 "2022-03-28T13:30:39Z")

</div>

`getproperty` is the function being called with the dot syntax, so you can broadcast that function directly:

```julia
julia> getproperty.(mylist, :id)
3-element Vector{Int64}:
 1
 2
 1

```

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [March 28, 2022, 8:43pm UTC](https://discourse.julialang.org/t/is-it-possible-to-broadcast-the-property-of-a-structure/78615/3 "2022-03-28T20:43:36Z")

</div>

The comprehension seems to be much more efficient than `getproperty` (at least in Julia 1.7.2):

```julia
struct Foo
    id::Int64
end
mylist = [Foo(rand(1:10)) for _ in 1:10_000]

f(mylist) = [e.id for e in mylist]
g(mylist) = getproperty.(mylist, :id)

@btime f($mylist) # 5.3 μs (2 allocs: 78 KiB)
@btime g($mylist) # 152 μs (10003 allocs: 234 KiB)

```
