# Julia 0.7 flattening of Nested Tuples

**URL:** <https://discourse.julialang.org/t/julia-0-7-flattening-of-nested-tuples/16860>\
**Category:** Numerics\
**Created:** [October 27, 2018, 1:45pm UTC](https://discourse.julialang.org/t/julia-0-7-flattening-of-nested-tuples/16860 "2018-10-27T13:45:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ultima](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ultima/32/4244_2.png) [@Ultima](https://discourse.julialang.org/u/Ultima)\
**Post date:** [October 27, 2018, 1:45pm UTC](https://discourse.julialang.org/t/julia-0-7-flattening-of-nested-tuples/16860/1 "2018-10-27T13:45:48Z")

</div>

I’ve implemented a Julia Version of a “Multiplicative Partitions of a Number”. Since 0.7 the State, start … iteration changed. I got a pre 0.7 Version of a Tuple flattener on this Page: [Nested list comprehensions in Julia - Stack Overflow](https://stackoverflow.com/questions/21129125/nested-list-comprehensions-in-julia)

```julia
function flatten(x, y)
      state = start(x)
       if state==false
          push!(y, x)
    else
        while !done(x, state) 
          (item, state) = next(x, state) 
          flatten(item, y)
        end 
    end
    y
end
flatten(x)=flatten(x,Array(Any, 0))

```

This doesn’t work anymore in 0.7, and the alternative:

> collect(Iterators.flatten(Iterators.flatten([(1,2,[3,3,3,3]),[4,5],6])))

only works to a nest-level of 4, while i need to flatten the tuples to an arbitrary depth.  
Can someone tell me how to alter the **flatten** function code to work with 0.7?

---

<div class="post-metadata">

**Author:** ![Ultima](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ultima/32/4244_2.png) [@Ultima](https://discourse.julialang.org/u/Ultima)\
**Post date:** [October 28, 2018, 4:01pm UTC](https://discourse.julialang.org/t/julia-0-7-flattening-of-nested-tuples/16860/2 "2018-10-28T16:01:09Z")

</div>

Found it:

```julia
function flatten(arr)
	rst = Any[]
	grep(v) = for x in v
				if isa(x, Tuple) 
				grep(x) 
				else push!(rst, x) end
				end
	grep(arr)
	rst
end

```
