Open
Conversation
Currently, the only way to create an empty CSV with headers is by using a pipe that takes explicit headers. The more comfortable encodeUsingFirstHeaders requires the CSV to be non-empty. This adds a encodeUsingStaticHeaders pipe that takes the necessary header information from a new type class StaticHeaders. To facilitate adoption, the generic derivation now derives CsvRowEncoder instances that also implement StaticHeaders.
ybasket
commented
Apr 3, 2026
satabin
reviewed
Apr 3, 2026
| @@ -0,0 +1,46 @@ | |||
| /* | |||
| * Copyright 2024 fs2-data Project | |||
satabin
reviewed
Apr 3, 2026
|
|
||
| /** Type class for types that have statically known headers. This is useful for encoding/decoding CSV rows | ||
| * where the headers are fixed and can be determined at compile time. */ | ||
| trait StaticHeaders[T, H] { |
Member
There was a problem hiding this comment.
I really think we need to drop this parametric header type for version 2, it makes things harder to read for no real benefit. Or do we have a strong point in favor of keeping it? I don't remember why I did that choice at the time...
Collaborator
Author
There was a problem hiding this comment.
Yeah, I think its weight is not justified by its value. Especially as we also don't use it in the generic module (which could also be generic over the header type via the type classes instead of being hardcoded to String, but isn't). And something like a NonEmptyMap[MyEnumType, String] (roughly isomorphic to our CsvRow) can be decoded from String headers almost as easily.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, the only way to create an empty CSV with headers is by using a pipe that takes explicit headers. The more comfortable
encodeUsingFirstHeadersrequires the CSV to be non-empty.This PR adds a
encodeUsingStaticHeaderspipe that takes the necessary header information from a new type classStaticHeaders. To facilitate adoption, the generic derivation now derivesCsvRowEncoderinstances that also implementStaticHeaders.Still missing, will add once it's clear this PR is going somewhere:
genericbecauseDerivedCsvRowEncoderis public. I don't think it would be a problem