https://kotlinlang.org logo
s

spand

06/26/2019, 7:41 AM
Is it possible to create my own operator on
SqlExpressionBuilder
somehow ?
t

tapac

06/26/2019, 11:04 AM
With
Expression<*>
as a receiver? I guess it's impossible as you need to have 2 receivers on a single function. Why do you need that? To reduce function scope?
s

spand

06/26/2019, 11:07 AM
I wanted to make my own helper functions.. ie.
inInterval
that checks a column c is: interval.start <= c && c < interval.end
t

tapac

06/26/2019, 12:03 PM
The only thing is extension on
Expression<DateTime?>.inInterval(..)
but it will be available out of
SqlExpressionBuilder
scope.
s

spand

06/26/2019, 12:06 PM
Yeah that what I ended up doing and importing
greaterEq
, and
less
. Would just be nice to have it encapsulated like the rest.
Maybe it ought to be a language proposal to have multiple extension receivers.
t
Not sure what this is exactly about you need,
s

spand

06/26/2019, 12:16 PM
Thanks. Will take a look
t

tapac

06/26/2019, 12:19 PM
I found interesting approach here (https://discuss.kotlinlang.org/t/declare-member-extensions-outside-the-class/6759/6?u=tapac)
Copy code
val SqlExpressionBuilder.inInterval: ExpressionWithColumnType<DateTime?>.(Interval) -> Expression<Boolean> get() = { interval ->
    val expr = this
    (expr greater interval.start) and (expr less interval.end) 

}

fun main() {
    Op.build {
        val expr = dateLiteral(DateTime.now())
        expr.inInterval(3)
    }
}
s

spand

06/26/2019, 12:22 PM
That is an interesting approach 😉
We only use infix however so I think I prefer the fun
2 Views