resultBuilder inside a resultBuilder

In trying to keep my sanity with a well known Apple framework, I'm trying to do some wrapping to make the code a bit more compact.

In general, if I have a black box result builder closure with a parameter:

RBfoo { rbFooProxy in 
   RBbar {
     DoSomethingClever(rbFooProxy.member)
   }
}

I would like to combine these so that I get:

RBfooBar { rbFooProxy in
   DoSomethingClever(rbFooProxy.member)
}

but I can't quite wrap my head around how to do this. Any pointers?

I mean, couldn't you just define it as

func RBfooBar(@Bar body: (FooProxy) -> Bar.Expression) -> Foo.FinalResult {
  RBfoo { proxy in
    RBbar {
      body(proxy)
    }
  }
}

?

1 Like

That seems right, but I don't know why, and I find that unsettling.

The code that fully worked, for those who might have wondered:

func scrollViewCombo<Content: View>(@ViewBuilder body: @escaping (ScrollViewProxy) -> Content) -> ScrollViewReader<ScrollView<Content>> {
     ScrollViewReader { proxy in
        ScrollView {
            body(proxy)
        }
    }
}

Now that I know it works, I shall stare at it in the hopes that the logic reveals itself to me.