【发布时间】:2018-04-26 15:08:19
【问题描述】:
我有一个站点,我想根据某些条件执行不同的查询,有时会返回一个导致空结果集的查询。
def myQuery(something: Boolean): Query[A, B, Seq] = {
if(something)
for {
x <- table
y <- othertable
// ...
} yield a
else
Query.empty
}
但是,Query.empty 的类型为 Query[Unit, Unit, Seq]。导致我不得不写这个:
def myQuery(): Query[A, B, Seq] = {
if(something)
for {
x <- table
y <- othertable
// other logic yielding a moderatly complex `A` and `B`
} yield b
else
for {
x <- table
y <- othertable
// Parts of logic copy pasted
if false
} yield b
}
是否有更简单/更清晰的方法来生成正确键入的空Query?
【问题讨论】: