I'd like to overload the spread `*` operator, so t...
# language-proposals
e
I'd like to overload the spread
*
operator, so that this:
Copy code
val s = "pos (%8.2f,%8.2f), uv (%.6f,%.6f)\n".format(v.pos.x, v.pos.y, v.uv.x, v.uv.y, v.col)
may become
Copy code
val s = "pos (%8.2f,%8.2f), uv (%.6f,%.6f)\n".format(*v.pos, *v.uv)
z
You can't, kotlin does not allow you to overload that operator. https://kotlinlang.org/docs/reference/operator-overloading.html#unary-operations
Some alternatives: - implement toString on whatever classes pos and uv are. - Write a custom format extension function that takes your specific types (I can't recall off the top of my head if the function resolution rules will actually let this work, but worst case you can give it a different name).
r
You can't, kotlin does not allow you to overload that operator.
Which is probably why it was posted in the proposals channel 😀
🙂 5
z
Oops, lol, my bad.
I bet this could be rolled into a general “overloadable destructuring” feature.