Skip to content
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

Added Test and Function Read with Header From Sequence #43

Closed
wants to merge 1 commit into from

Conversation

blackmo18
Copy link
Contributor

#40

Hi this may not be exactly as what the issue, but I think it could serve the same purpose
Kind regards.

Copy link
Owner

@doyaaaaaken doyaaaaaken left a comment

Choose a reason for hiding this comment

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

Thank you for sending PR!
Not bad, but please consider my review comment.

@@ -50,6 +51,17 @@ class CsvFileReader internal constructor(
}
}

fun readAllWithHeaderFromSequence( body: CsvHeader.(index: Int, list: List<String>) -> Unit) {
Copy link
Owner

Choose a reason for hiding this comment

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

Exactly, this method signature enables to write clean code by restricting variable scope with block nesting.
https://github.com/doyaaaaaken/kotlin-csv/pull/43/files#diff-d57edaac2d72b352e33e19d683b773b8R225-R231

But, the below method signature would be better because it returned Sequence.
fun readWithHeaderAsSequence(): Sequence<Map<String, String>>

You could handle returned Sequence value like below code. It'd be cleaner and more declarative.

readWithHeaderAsSequence()
                .filter { row -> requireNotNull(row["col1"]).toInt() > 0 }
                .filter { row -> requireNotNull(row["col2"]) != "hoge" }
                .toList()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,

I also agree with the comment above. As I was looking at the source, the implementation of method fun readAllWithHeader(): List<Map<String, String>> it was initially as a sequence then converted to list.

So I guess, it just needs to be refactored into 2 different methods?

Copy link
Owner

Choose a reason for hiding this comment

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

Simple solution, and I agree with your opinion!

@doyaaaaaken
Copy link
Owner

Close this PR because it continued on PR #44 .

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.

None yet

2 participants