pub fn merge_cell_shifts(instructions: Vec<Node>) -> Vec<Node> {
    instructions
        .into_iter()
        .coalesce(|prev_instruction, instruction| {
            if let Node::CellShift {
                amount: prev_amount,
                loc: prev_loc,
            } = prev_instruction
            {
                if let Node::CellShift { amount, loc } = instruction {
                    return Ok(Node::CellShift {
                        amount: amount + prev_amount,
                        loc: prev_loc.merge(loc),
                    });
                }
            }
            Err((prev_instruction, instruction))
        })
        .filter(|instruction| {
            if let Node::CellShift { amount: 0, .. } = *instruction {
                return false;
            }
            true
        })
        .map_loops(merge_cell_shifts)
}
/// Merges concurrent cell shifts into 1 shift
Merges concurrent cell shifts into 1 shift
Merges concurrent cell shifts into 1 shift
pub fn merge_cell_shifts(instructions: Vec<Node>) -> Vec<Node> {
    instructions
        .into_iter()
        .coalesce(|prev_instruction, instruction| {
            if let Node::CellShift {
                amount: prev_amount,
                loc: prev_loc,
            } = prev_instruction
            {
                if let Node::CellShift { amount, loc } = instruction {
                    return Ok(Node::CellShift {
                        amount: amount + prev_amount,
                        loc: prev_loc.merge(loc),
                    });
                }
            }
            Err((prev_instruction, instruction))
        })
        .filter(|instruction| {
            if let Node::CellShift { amount: 0, .. } = *instruction {
                return false;
            }
            true
        })
        .map_loops(merge_cell_shifts)
}
pub fn merge_cell_shifts ( instructions : Vec < Node > ) -> Vec < Node > { instructions . into_iter ( ) . coalesce ( | prev_instruction , instruction | { if let Node :: CellShift { amount : prev_amount , loc : prev_loc , } = prev_instruction { if let Node :: CellShift { amount , loc } = instruction { return Ok ( Node :: CellShift { amount : amount + prev_amount , loc : prev_loc . merge ( loc ) , } ) ; } } Err ( ( prev_instruction , instruction ) ) } ) . filter ( | instruction | { if let Node :: CellShift { amount : 0 , .. } = * instruction { return false ; } true } ) . map_loops ( merge_cell_shifts ) }
Merges concurrent cell shifts into 1 shift
Merges concurrent cell shifts into 1 shift
instructions
Vec<Node>
instructions
Vec<Node>