-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Emit an error if row and header size mismatch #622
Conversation
cb7f54e
to
812c16d
Compare
@@ -217,6 +221,27 @@ package object csv { | |||
} | |||
} | |||
|
|||
/** Encode a specified type into a CSV prepending the given headers. */ | |||
def encodeWithGivenHeaders[T]: PartiallyAppliedEncodeWithGivenHeaders[T] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wdyt about renaming to encodeWithHeaders
? We already have encodeWithoutHeaders
, so the naming feels a bit more consistent then the WithGiven
.
No strong opinion on this though, just noticed it, decide as you see fit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to keep consistent naming between the high and low level naming. Since the low level naming cannot be writeWithHeaders
(this is the deprecated one) and high-level cannot be encodeGivenHeaders
(this is the deprecated one), I settled for merging both.
val input = List( | ||
Row(NonEmptyList.of("a", "b", "c"), Some(1)), | ||
Row(NonEmptyList.of("d", "e"), Some(2)), | ||
Row(NonEmptyList.of("f", "g", "h", "i"), Some(3)), | ||
Row(NonEmptyList.of("j", "k", "l"), Some(4)) | ||
) | ||
val headers = NonEmptyList.of("first", "second", "third") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val input = List( | |
Row(NonEmptyList.of("a", "b", "c"), Some(1)), | |
Row(NonEmptyList.of("d", "e"), Some(2)), | |
Row(NonEmptyList.of("f", "g", "h", "i"), Some(3)), | |
Row(NonEmptyList.of("j", "k", "l"), Some(4)) | |
) | |
val headers = NonEmptyList.of("first", "second", "third") | |
val headers = NonEmptyList.of("first", "second", "third") | |
val input = List( | |
Row(NonEmptyList.of("a", "b", "c"), Some(1)), | |
Row(NonEmptyList.of("d", "e"), Some(2)), | |
Row(NonEmptyList.of("f", "g", "h", "i"), Some(3)), | |
Row(NonEmptyList.of("j", "k", "l"), Some(4)) | |
) |
I find this test case slightly annoying to read, but except for this reordering (so it matches output order) and maybe adding some unapplySeq
in cats itself, I found no better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thought on this snippet (not to be done in this PR though): Maybe a row"…, …, …"
string interpolator could be nice, especially for our tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried adding unapplySeq
to cats, unfortunately it doesn't work because NonEmptyList
is a case class
and hence has a generated unapply
that takes precedence. Would need a dedicated extractor object.
Fixes #621
A new method is created and the old one is deprecated to keep binary compatibility.