Hello, I was wondering if there is a way to pass a...
# announcements
a
Hello, I was wondering if there is a way to pass an operator (like >, =< etc) as a parameter to a function. Since e.g. comparison operators are translated to a.compareTo(b) function calls how is it possible to pass the actual operator in a function like: fun someFunction(operator: Int.(Int) -> Boolean)
d
There is no dedicated operator function for the comparison operators, they use
compareTo
. So for that you'd have to pass
Int::compareTo
and use that inside
someFunction
.
Otherwise you need to pass a lambda:
someFunction { a, b -> a < b }
a
hm. I think lamda may work
thank u