Source

Branch

1/ @hasen_95dx

@nicbarkeragain

this particular case though is easily solved with defer or even closures

Container(...., func() {
    // container is closed when this func exits
})

2/ @nicbarkeragain

@hasen_95dx

Yes, I tend to use the “single iteration for loop” macro trick in C to do this exact thing with scope, but there are still a bunch of cases where you might want to have a direct API that you can use to call open / close:

3/ @nicbarkeragain

@hasen_95dx

I’ve also found explicit open / close to be very useful in rendering tree views / arbitrary recursive hierarchy etc.

4/ @hasen_95dx

@nicbarkeragain

Right. With the closure approach it would have to change.

body := func() { … }

if condition { Container(…, body) }
else { body() }