Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add map and andThen override to RowParser #94

Merged
merged 1 commit into from
Jan 21, 2025
Merged

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 parse(row: SqlRow): A

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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants