Skip to content

Commit

Permalink
Add map and andThen override to RowParser
Browse files Browse the repository at this point in the history
Override `andThen` to return a RowParser instead of just a A => B, and add a map function that is an
alias to andThen.
  • Loading branch information
tmccombs committed Jan 21, 2025
1 parent 959e783 commit ed6d6f1
Showing 1 changed file with 7 additions and 1 deletion.
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))
}

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

object RowParser {
Expand Down

0 comments on commit ed6d6f1

Please sign in to comment.