Joe
01/30/2019, 11:10 PMeq()
method -- i need the same cast if i change it to <out Any>, and if i change it to <in Any> the createCondition()
function works but I can't invoke it in `main()`:
data class ConditionData<T>(
val field: Field<T>,
val value: String,
val transform: (String) -> T
)
fun createCondition(vararg things: ConditionData<*>): Condition {
return things
.map {
val value = it.transform.invoke(it.value)
(it.field as Field<Any>).eq(value)
}
.reduce { a, b -> a.and(b) }
}
fun main() {
print(
createCondition(
ConditionData(DSL.sum(Tables.DATA.WATCH_TIME), "1234567.234") { s -> BigDecimal(s) },
ConditionData(Tables.DATA.MONTH, "2018-07-01") { s -> LocalDate.parse(s) },
ConditionData(Tables.DATA.CHANNEL, "HBO") { s -> s }
)
)
}
output of the main is correct:
(
sum("data"."watch_time") < 1234567.234
and "data"."month" < date '2018-07-01'
and "data"."channel" < 'HBO'
)
ghedeon
01/31/2019, 12:04 AMField<T>
with T
here?
val value = it.transform.invoke(it.value)
(it.field as Field<Any>).eq(value)
Joe
01/31/2019, 12:56 AM