Skip to content

Conversation

@tmccombs
Copy link
Contributor

Override andThen to return a RowParser instead of just a A => B, and add a map function that is an alias to andThen.

Override `andThen` to return a RowParser instead of just a A => B, and add a map function that is an
alias to andThen.
@tmccombs tmccombs requested review from gregghz and sriraamas January 21, 2025 18:35
def apply(row: SqlRow) = parse(row)

override def andThen[B](g: A => B): RowParser[B] = new RowParser[B] {
def parse(row: SqlRow): B = g(self.parse(row))

Choose a reason for hiding this comment

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

Nit: self.parse can be replaced with RowParser.this.parse.

Copy link
Contributor

@coreywoodfield coreywoodfield Jan 21, 2025

Choose a reason for hiding this comment

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

I don't think so—the inner block we're in is also a RowParser, so I think that would just be the same as parse

Choose a reason for hiding this comment

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

I think Scala is smart enough to realize it's different:
https://scastie.scala-lang.org/eJ4rnnv4RAC1pOtgRslsZQ

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even if that does work, I think using the self is more clear.

Choose a reason for hiding this comment

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

Fair enough.

@tmccombs tmccombs merged commit 4c171f9 into master Jan 21, 2025
3 checks passed
@tmccombs tmccombs deleted the map-rowparser branch January 21, 2025 21:28
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.

4 participants