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

Improve handling of headers #16

Merged
merged 6 commits into from
Mar 1, 2020

Conversation

ybasket
Copy link
Collaborator

@ybasket ybasket commented Feb 27, 2020

Supersedes #15, see discussion there for motivating use cases.

Includes:

  • Change ParseableHeader to parse all header columns at once to allow for more elaborated validation
  • Add Row class to represent csv rows without headers properly
  • Make CsvRow a case class extending Row and make headers non-optional
  • Introduce skipHeaders and withHeaders pipes to cover all combinations of headers being present in the file and in the desired output

Header(firstRow) match {
case Left(error) => Pull.raiseError[F](error)
case Right(headers) if headers.length =!= firstRow.length =>
Pull.raiseError[F](new HeaderError("The count of headers must match the count of columns"))
Copy link
Member

Choose a reason for hiding this comment

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

Potentially add the sizes in the message, I think it can be useful when this happens, to debug

def attemptDecode[F[_], R](implicit F: Applicative[F],
R: RowDecoder[R]): Pipe[F, NonEmptyList[String], DecoderResult[R]] =
_.map(R(_))
/** Transforms a stream of raw CSV rows into rows, skipping the first line to ignore the headers. */
Copy link
Member

Choose a reason for hiding this comment

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

First "line" is confusing in the context of CSV, I prefer to use "row", as it might span several lines.

@satabin
Copy link
Member

satabin commented Feb 29, 2020

2 minor comments, otherwise LGTM.

@ybasket
Copy link
Collaborator Author

ybasket commented Mar 1, 2020

2 minor comments, otherwise LGTM.

Both addressed in afe6c82 :)

@satabin satabin merged commit c4a9083 into gnieh:master Mar 1, 2020
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