# Pointwise getproperty

**URL:** <https://discourse.julialang.org/t/pointwise-getproperty/66806>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 22, 2021, 3:36pm UTC](https://discourse.julialang.org/t/pointwise-getproperty/66806 "2021-08-22T15:36:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![peteole](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peteole/32/209790_2.png) [@peteole](https://discourse.julialang.org/u/peteole)\
**Post date:** [August 22, 2021, 3:36pm UTC](https://discourse.julialang.org/t/pointwise-getproperty/66806/1 "2021-08-22T15:36:53Z")

</div>

Hi,  
I am thinking about the neatest way to neatest way to project an iterable of structs to an iterable of a member of each of these structs. For example:

```julia
struct Point
x::Int
y::Int
end
points=[Point(1,11),Point(2,12)]

#1.
xCoordinates=map(points) p do p.x end
#2.
xCoordinates=getproperty.(points,:x)
#3. (does not work)
xCoordinates=points..x

```

1. & 2. work, but I do not find these syntaxes particularly beautiful. Is there a way to do it similarly to 3. that works?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [August 22, 2021, 3:52pm UTC](https://discourse.julialang.org/t/pointwise-getproperty/66806/2 "2021-08-22T15:52:02Z")

</div>

The closest approximation would be:

```julia
x(p::Point) = p.x

xCoordinates = x.(points)

```

That’s pretty common in Julia code, since it’s common to provide public accessor functions for the (typically private) fields of a struct.

Of course, you can always define a macro:

```julia
julia> macro ..(a, b::Symbol)
         quote
           getproperty.($(esc(a)), $(QuoteNode(b)))
         end
       end
@.. (macro with 1 method)

julia> @.. points x
2-element Vector{Int64}:
 1
 2

```

But I’d still recommend just making the accessor function instead.
