/// Given a series of branch expressions, this will nest them together
/// so that they result in a single nested branch expression
///
/// # Example
/// Given:
/// if foo1 { body1 } else {}
/// if foo2 { body2 } else {}
/// if foo3 { body3 } else {}
///
/// Results in:
/// if foo1 { body1 } else { if foo2 { body2 } else { if foo3 { body3 } else {} } }
Given a series of branch expressions, this will nest them together
so that they result in a single nested branch expression
Given a series of branch expressions this will nest them together so that they result in a single nested branch expression
fn nest_else_ifs(branches: VecDeque<Expression>, else_block: Option<Block>) -> Block {
    branches.into_iter().rev().fold(else_block, |acc, mut br| {
        Some(vec![Statement::Expression {
            expr: {
                match br {
                    Expression::Branch {ref mut otherwise, ..} => {
                        *otherwise = acc;
                    },
                    _ => unreachable!(),
                };
                br
            },
        }])
    }).unwrap()
}
fn nest_else_ifs ( branches : VecDeque < Expression > , else_block : Option < Block > ) -> Block { branches . into_iter ( ) . rev ( ) . fold ( else_block , | acc , mut br | { Some ( vec ! [ Statement Expression { expr { match br { Expression Branch { ref mut otherwise } { otherwise acc } unreachable ( ) } br } } ] ) } ) . unwrap ( ) }
Given a series of branch expressions, this will nest them together
so that they result in a single nested branch expression
Given a series of branch expressions this will nest them together so that they result in a single nested branch expression
branches
VecDeque<Expression>
else_block
Option<Block>
example
if foo1 { body1 } else {}
if foo2 { body2 } else {}
if foo3 { body3 } else {}

Results in:
if foo1 { body1 } else { if foo2 { body2 } else { if foo3 { body3 } else {} } }
if foo1 { body1 } else {} if foo2 { body2 } else {} if foo3 { body3 } else {} Results in : if foo1 { body1 } else { if foo2 { body2 } else { if foo3 { body3 } else {} } }