Q:

Recursively loop through array of arrays using functional

I want to loop through my view subviews, and for each subview loop through its subviews and etc.
so let say I have the following code:
let view = myVC.view
view.backgroundColor = UIColor.clearColor()

then repeat this same for each subview. I want to do it functionally. 
any insight is much appreciated. 
EDIT:
to make it clear
I'm looking for something like this:
view.subviews.chanageColor() { (aView, aColor) in
aView.backgroundColor = aColor
}

but it should be recursive it goes to each view subview.

A:

Something like this?
func makeAllSubviewsClear(view: UIView!)
{
    view.backgroundColor = UIColor.clearColor()
    for eachSubview in view.subviews
    {
        makeAllSubviewsClear(eachSubview)
    }
}

called via:
let view = myVC.view
makeAllSubviewsClear(view)

A:

Use a queue instead of recursing.
I think you could do something like this...
extension UIView {    
    func changeColor(color: UIColor) {
        var queue = [self]

        while let view = queue.first() {
            queue += view.subviews

            view.backgroundColor = color

            queue.remove(view)
        }
    }
}

I'd do it with a queue instead of doing it recursively. That method isn't functional though.
Doing what your question wanted
You could do this way, which is what you put in your question as what you wanted to do.
extension UIView {
    // this name isn't very good but you get the idea
    func applyChangeToAllSubviews(block: (UIView) -> ()) {
        var queue = [self]

        // I don't have my dev computer dos not sure of the syntax
        while let view = queue.first() {
            queue += view.subviews

            block(view)

            queue.remove(view)
        }
    }
}

Then run it like...
someView.applyChangeToAllSubviews {
    view in
    view.backgroundColor = UIColor.whiteColor()
}

I guess that's a bit more functional... ish.

