# Loop Fusion usage between Arrays of custom structs

**URL:** <https://discourse.julialang.org/t/loop-fusion-usage-between-arrays-of-custom-structs/18969>\
**Category:** General Usage\
**Tags:** loops\
**Created:** [December 25, 2018, 3:09am UTC](https://discourse.julialang.org/t/loop-fusion-usage-between-arrays-of-custom-structs/18969 "2018-12-25T03:09:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [December 25, 2018, 4:04am UTC](https://discourse.julialang.org/t/loop-fusion-usage-between-arrays-of-custom-structs/18969/2 "2018-12-25T04:04:45Z")

</div>

First, what you create in `p` is a single `point` object, with 100 element `x` and `y` vectors. I don’t think this is what you want – you probably want a vector with 100 `Point` objects?

Second, unless I’m mistaken, to use the dot operators (broadcasting) with custom types, you need to wrap it in `Ref` in order to treat it as a scalar (or put it in a tuple or array). This was discussed at length in [this topic](https://discourse.julialang.org/t/recent-broadcast-changes-iterate-by-default-scalar-struct-and/11178).

This is how I would write your code:

```julia
struct Point{T}
  x::T
  y::T
end

points = [Point(rand(), rand()) for n = 1:5]

Base.:+(a::Point, b::Point) = Point(a.x+b.x , a.y+b.y)

point = Point(1, 1)

# these all give the same result, pick one:
points .+ Ref(point)
points .+ (point,)
points .+ [point] # note: extra allocation, slightly slower

```

---

_[View the full topic](https://discourse.julialang.org/t/loop-fusion-usage-between-arrays-of-custom-structs/18969)._
