some sample would help. but if you want to provide...
# announcements
a
some sample would help. but if you want to provide some compatibility with outside consumers:
Copy code
typealias Coordinate2D = Triple<Int, Int, String>
operator fun Coordinate2D.invoke(x: Int, y: Int, description: String) = Coordinate2D(x, y, description)
r
Your invoke requires a instance to exist already...
a
what do you mean. it fakes a constructor on a
typealias
to
Triple
of a certain type thats called
Coordinate2D
and gives it named arguments
r
operator fun Coordinate2D.invoke
works on an instance of
Triple<Int, Int, String>
, so it would be used like so:
Copy code
val tri = Triple(5, 6, "test")
val coord = tri(7, 8, "test-2")
I think you want
Copy code
fun Coordinate2D(x: Int, y: Int, description: String): Coordinate2D = Triple(x, y, description)
a
I guess so. might as well just make it a function I guess at that point named
coordinate()
. haha.
👍 1