-
-
Notifications
You must be signed in to change notification settings - Fork 30
Introduce StaticHeaders type class for CSV #757
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Copyright 2024 fs2-data Project | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to update that year... |
||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package fs2.data.csv | ||
|
|
||
| import cats.Functor | ||
| import cats.data.NonEmptyList | ||
|
|
||
| /** 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
| def headers: NonEmptyList[H] | ||
| } | ||
|
|
||
| object StaticHeaders { | ||
| @inline | ||
| def apply[T, H](implicit sh: StaticHeaders[T, H]): StaticHeaders[T, H] = sh | ||
|
|
||
| @inline | ||
| def instance[T, H](hs: NonEmptyList[H]): StaticHeaders[T, H] = | ||
| new StaticHeaders[T, H] { | ||
| override def headers: NonEmptyList[H] = hs | ||
| } | ||
|
|
||
| implicit def headerFunctor[T]: Functor[StaticHeaders[T, *]] = new Functor[StaticHeaders[T, *]] { | ||
| override def map[A, B](fa: StaticHeaders[T, A])(f: A => B): StaticHeaders[T, B] = instance(fa.headers.map(f)) | ||
| } | ||
|
|
||
| implicit def forWriteableHeader[T, H](implicit | ||
| W: WriteableHeader[H], | ||
| H: StaticHeaders[T, H]): StaticHeaders[T, String] = | ||
| instance(WriteableHeader[H].apply(H.headers)) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.