Skip to content

Instantly share code, notes, and snippets.

@thsutton
Created October 25, 2017 00:35
Show Gist options
  • Save thsutton/e05719d8cda48ad59f9d21bfc39d87e6 to your computer and use it in GitHub Desktop.
Save thsutton/e05719d8cda48ad59f9d21bfc39d87e6 to your computer and use it in GitHub Desktop.
trait Queries {
type K
trait Query {
def from(k: K): Query
}
def select(where: String) = Select(where)
def scan() = Scan()
case class Select(where: String, private val from: Option[K] = None) {
def from(k: K): Select = copy(from=Some(k))
}
case class Scan(private val from: Option[K] = None) {
def from(k: K): Scan = copy(from=Some(k))
}
}
case class Table[K, V](name: String) extends Queries
object Foo {
val table = Table[String, Int]("aTable")
val q = table.scan()
val next = Some("x")
val f1 = next.map(q.from)
val f2 = next.map(q.from _)
val f3 = next.map(q.from(_))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment