What would be good purely functional data structures for text editors? I want to be able to insert single characters into the text and delete single characters from the text with acceptable efficiency, and I would like to be able to hold on to old versions, so I can undo changes with ease.
Should I just use a list of strings and reuse the lines that don’t change from version to version?
A
Vector[Vector[Char]]would probably be a good bet. It is anIndexedSeqso has decent update / prepend / update performance, unlike theListyou mention. If you look at Performance Characteristics, it’s the only immutable collection mentioned that has effective constant-time update.