Port of agoragames's bracket_tree to Scala