# Broadcast and Map on Set have inconsistent behaviors

**URL:** <https://discourse.julialang.org/t/broadcast-and-map-on-set-have-inconsistent-behaviors/10522>\
**Category:** General Usage\
**Created:** [April 25, 2018, 1:16am UTC](https://discourse.julialang.org/t/broadcast-and-map-on-set-have-inconsistent-behaviors/10522 "2018-04-25T01:16:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![babaq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/babaq/32/891_2.png) [@babaq](https://discourse.julialang.org/u/babaq)\
**Post date:** [April 25, 2018, 1:16am UTC](https://discourse.julialang.org/t/broadcast-and-map-on-set-have-inconsistent-behaviors/10522/1 "2018-04-25T01:16:18Z")

</div>

```nohighlight
x,y,z=1,2,3
a=Set()
b=Set()
push!(a,:x,:y,:z)
push!(b,1,2,3)

log.(b) # error
map(log,b) # work

map(string,a) # work, gives Set(String["x", "z", "y"])
string.(a) # no error, but gives a string "Set(Any[:y, :z, :x])"

```

I find it rather confusing and not fit to common expectations. i am testing on win\_x64 v0.6.2.

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [April 25, 2018, 2:49am UTC](https://discourse.julialang.org/t/broadcast-and-map-on-set-have-inconsistent-behaviors/10522/2 "2018-04-25T02:49:24Z")

</div>

You should not, in general, expect `broadcast` and `map` to have the same behavior, they are named differently for a reason.

The basic philosophy (as I understand it) is that `map` is for general iterable collections while `broadcast` is for objects with an `AbstractArray`-like behavior. In light of this, the reason you shouldn’t necessarily expect `broadcast` to work for `Set` is because sets are collections with no ordering.

As an example:

```julia
x = [1, 2, 3]
y = [4, 5, 6]
x .* y # returns [4, 10, 18]

```

In this operation ordering was clearly very important: it only makes sense because `x` and `y` have a well-defined order. Meanwhile, `b .* y` (with `b` the set you defined above) would be undefined because the ordering of `b` is not defined.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [April 25, 2018, 2:57am UTC](https://discourse.julialang.org/t/broadcast-and-map-on-set-have-inconsistent-behaviors/10522/3 "2018-04-25T02:57:00Z")

</div>

Broadcasting over sets is deprecated on 0.7 for precisely this reason.

---

<div class="post-metadata">

**Author:** ![babaq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/babaq/32/891_2.png) [@babaq](https://discourse.julialang.org/u/babaq)\
**Post date:** [April 25, 2018, 5:34pm UTC](https://discourse.julialang.org/t/broadcast-and-map-on-set-have-inconsistent-behaviors/10522/4 "2018-04-25T17:34:10Z")

</div>

Thanks for the explaination @ExpandingMan.
