seems like a workaround, but i still have to creat...
# announcements
l
seems like a workaround, but i still have to create an instance of BinarySameType if i want to pass it in as a parameter. Is there a more functional solution?
a
luckymerlin: I don't think so. They are called "extensions declared as members", but there's no syntax to declare them as extensions themselves
Thinking of
(T,T)->T
functions - are there any case where they might return anything but one of their arguments?
Copy code
inline fun<T> (()->Boolean).asChoice(a:T,b:T):T = if (this()) a else b

fun <U> weirdChoice(random:()->Boolean, c1: U, c2: U): U {
	if (random.asChoice(true, false)) {
		return random.asChoice(c1, c2)
	} else {
		return random.asChoice(c2, c1)
	}
}
l
I see. Never knew i could add extension methods to things like
()->Boolean
. Thanks for your detailed explanation. ­čśä