https://kotlinlang.org logo
Title
h

Hullaballoonatic

12/01/2019, 1:52 AM
It's great that you can pass method references as arguments like so:
operator fun Vector.times(scalar: Double) = mapToVector(scalar::times)
but since division isn't commutative, i can't use the same syntax for that, unless there's a way I don't know of?
operator fun Vector.div(divisor: Double) = mapToVector { it / divisor }
d

Dico

12/01/2019, 7:36 AM
You could 0ass
divisor
as a second parameter to mapToVector and expect a lambda that takes 2 doubles, the second one being the divisor. Then you can pass Double::div.