Skip to content

introduce appendLines method in IO. #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 11, 2024

Conversation

trilleplay
Copy link
Contributor

Adds appendLines to the IO api, which lets users easily append a sequence of strings to a file that already exists.

Solves #45 .

Adds appendLines to the IO api, which lets users
easily append a sequence of strings to a file
that already exists.
Also refactors the appendLines method to use the
newly introduced function.
@bjornregnell
Copy link
Member

I guess we should have trailing "\n" in the line-writers.

@trilleplay
Copy link
Contributor Author

Added a trailing newline @bjornregnell

@@ -51,7 +51,7 @@ object IO:
* @param enc the encoding of the file.
* */
def saveLines(lines: Seq[String], fileName: String, enc: String = "UTF-8"): Unit =
saveString(lines.mkString("\n"), fileName, enc)
saveString(lines.mkString("\n") + "\n", fileName, enc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if lines are empty it should not write so better use mkString("", "\n", "\n") see docs for mkString to double-check the behavior or test in repl.

* @param enc the encoding of the file.
* */
def appendLines(lines: Seq[String], fileName: String, enc: String = "UTF-8"): Unit =
appendString(lines.mkString("\n"), fileName, enc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here it should be mkString("","\n","\n") I think, but check that it works as expected.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge this and then fix the correct behavior wen empty in a later commit.

@bjornregnell bjornregnell merged commit 0a2f802 into lunduniversity:master Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants