# Julia set data structure

**URL:** https://discourse.julialang.org/t/julia-set-data-structure/1292
**Category:** Offtopic
**Created:** [January 4, 2017, 9:39pm UTC](https://discourse.julialang.org/t/julia-set-data-structure/1292 "2017-01-04T21:39:13Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![harven](https://avatars.discourse-cdn.com/v4/letter/h/3da27b/32.png) [@harven](https://discourse.julialang.org/u/harven)
#### Post date: [January 4, 2017, 9:39pm UTC](https://discourse.julialang.org/t/julia-set-data-structure/1292/1 "2017-01-04T21:39:13Z")

</div>

I have a question on the `set` data structure in base Julia. As far as I understand, it is mutable, with O(1) membership, and adding an element is done with `push!`, which modifies the set.

Is there a “functional” set collection that is immutable and for which “adding” elements proceeds by sharing? Or a simple way to emulate this behavior with the default set structure? At the moment, I am using

```
 (s,x) -> union(s, Set(x))

```

in order to get a new set with `x` added without modifying `s` but it is probably not very efficient.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [January 4, 2017, 10:07pm UTC](https://discourse.julialang.org/t/julia-set-data-structure/1292/2 "2017-01-04T22:07:41Z")

</div>

[https://github.com/JuliaLang/FunctionalCollections.jl](https://github.com/JuliaLang/FunctionalCollections.jl) ?

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [January 4, 2017, 11:46pm UTC](https://discourse.julialang.org/t/julia-set-data-structure/1292/3 "2017-01-04T23:46:53Z")

</div>

That was written a while ago and has had very light maintenance, but it may work.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [January 5, 2017, 2:11am UTC](https://discourse.julialang.org/t/julia-set-data-structure/1292/4 "2017-01-05T02:11:59Z")

</div>

Well, it’s code is very simple. The tests fail, but it probably just needs some PRs to update from deprecated syntax. Sounds like a very good contribution opportunity for a newcomer.

---

<div class="post-metadata">

### Author: ![felix](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/felix/32/604_2.png) [@felix](https://discourse.julialang.org/u/felix)
#### Post date: [January 9, 2017, 5:02pm UTC](https://discourse.julialang.org/t/julia-set-data-structure/1292/5 "2017-01-09T17:02:44Z")

</div>

Chris, I was glad to see such an opportunity pointed out. Thanks!

I gave it a go here [RFC: syntax update by felixrehren · Pull Request #29 · JuliaCollections/FunctionalCollections.jl · GitHub](https://github.com/JuliaLang/FunctionalCollections.jl/pull/29) and would appreciate any help in improving the PR until it is useful 🙂
