laughinghan/mathquill — pull request #112 by laughinghan (2012-07-28 00:11:32+00:00)
Title: Refactor Parser::many and friends to fold rather than yield arrays

Instead of yielding an array, `Parser::many`, `times`, `atLeast`, and `atMost` take in two additional arguments, the arguments that the `fold` or `reduce` HOF takes: an initial result-so-far (or a function returning one, if it's going to be mutated) and a function that takes in two arguments, the combined/folded/reduced-result-so-far, and the result of this iteration. The final result is the final result-so-far.

`mathSequence`, `MathCommand::parser`, `RootTextBlock::renderLatex`, and even `Parser::atMost` are all simplified by this, while `many` and `times` are just as simple.