Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion relate/src/main/scala/com/lucidchart/relate/RowParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ import java.time.Instant
import scala.collection.mutable
import scala.language.higherKinds

trait RowParser[A] extends (SqlRow => A) {
trait RowParser[A] extends (SqlRow => A) { self =>
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.

}

def map[B](f: A => B): RowParser[B] = andThen(f)
}

object RowParser {
Expand Down