is there a way to make use of an infix modifier in...
# announcements
j
is there a way to make use of an infix modifier in a "postfix" kinda way, in othe words being allowed to exclude the trailing param? This is what i'm trying to do, but i'm forced to trail the DSL with a garbage value, in this case Unit
Copy code
infix fun postgresql.DESC(value: Unit): postgresql {
			return this
		}

	}


	fun main() {

		postgresql {
			SELECT (
				ListingTable::section, ListingTable::id,
				ListingImageTable::name, ListingImageTable::listingId
			) FROM (
				ListingTable::class
			) LEFT JOIN (
				ListingImageTable::class
			) ON (
				ListingTable::id == ListingImageTable::id
			) WHERE (
				true
			) ORDER BY(ListingTable::modified) DESC Unit


		}
n
what if the value param had a default value?
j
Copy code
'infix' modifier is inapplicable on this function: should not have varargs or parameters with default values
interesting idea though
b
Try value: Never
j
I've tried
Nothing
, after
DESC
, it still says
Expecting an element
b
Hold on, shouldn't infix functions have a receiver?
j
yes, each of those SELECT, FROM, LEFT, JOIN, ON, WHERE are functions that return the type Postgresql
b
No, I'm saying your DESC function declaration doesn't have a receiver
j
explain ?
b
First line of your snippet
Shouldn't it be infix fun postgresql.DESC(...)...
j
not quite following what is meant by a receiver, i've heard the terminology being used, but not sure what it means
b
Receiver is postgresql in my example above
It's the "this" of the function
j
ah although that makes no difference
Copy code
infix fun postgresql.DESC(value: Nothing): postgresql {
			return this
		}
i was trying to see if i can make it a regular function call, maybe even DESC() as a last resort
n
you could make DESC a parameter of BY instead
j
yeah, that's a possibility, then make DESC / ASC enums. Will need to see what other edge cases there are that requires an end-of-line type of infix function let me post this in language proposals, infix functions with default values making the input optional