lunduniversity / introprog-scalalib

Scala library with simple-to-use utilites for students of introductory programming. http://cs.lth.se/pgk/api
BSD 2-Clause "Simplified" License
60 stars 13 forks source link

Lack of easy way to append to text files. #45

Closed trilleplay closed 3 months ago

trilleplay commented 9 months ago

After reading though https://github.com/lunduniversity/introprog/issues/782 I think that some of the issues associated with Bank's saving and loading could be addressed by introducing a method that lets the user easily append to text files (since it might feel natural to do so in doEvent.)

I propose that a method be added for appending lines.

bjornregnell commented 9 months ago

Thanks for contributing! For completeness there should also be an appendString method that appends a string, similar to how saveLines also has a counterpart saveString. Ideally this would use the underlying appendability in java.io, see e.g. https://stackoverflow.com/a/24982850 See also https://github.com/lunduniversity/introprog-scalalib/issues/47

trilleplay commented 7 months ago

Thanks for contributing! For completeness there should also be an appendString method that appends a string, similar to how saveLines also has a counterpart saveString. Ideally this would use the underlying appendability in java.io, see e.g. https://stackoverflow.com/a/24982850 See also #47

It's been a while, but I've made the requested changes to my PR, I think I've written something that is what you're looking for @bjornregnell .

bjornregnell commented 3 months ago

@trilleplay You may want to see the correct implementation here to handle both empty seq and trailing newline: https://github.com/lunduniversity/introprog-scalalib/commit/482dcceaa4395504f4b10d9551391874ac313264

bjornregnell commented 3 months ago

I have also added some tests: https://github.com/lunduniversity/introprog-scalalib/commit/c80904a2da4899c33d66449eac5e1dc4a01ccec6