In the standard library `public fun <T> maxO...
# stdlib
s
In the standard library
public fun <T> maxOf(a: T, vararg other: T, comparator: Comparator<in T>): T
is conflicting with
public actual fun <T : Comparable<T>> maxOf(a: T, vararg other: T): T
for me 🤔 Even when
T
isn't
: Comparable<T>
. This is only fixed for me when moving the
comparator
parameter before the
vararg
one. Is this a known issue? I'm trying to define
sort
for
Comparable
and
Comparator
in Arrow to deprecate the
Order
typeclass into something more Kotlin idiomatic, but following the same patterns as the Kotlin Std I ran into this issue when writing tests.
i
It's expected that you can't pass a positional argument after varargs, though you can pass it in a named form:
maxOf(v1, v2, v3, v4, comparator = ...)
s
Right, but is it expected that Kotlin Std defines signatures that cannot be called without named params? I expected to be able to do
maxOf(v1, v2, v4, v4, comparatorV)
but that results in a type missmatch.
i
Yes, we do use such signatures sometimes. For example,
String.split
that takes vararg of delimiters in the first place:
string.split(",", ";", limit = 2)
s
All right, thanks for that background @ilya.gorbunov! We're doing some rework in Arrow towards 1.0.0 because we want to follow Kotlin Std's patterns. So I'm going to add these signatures to Arrow in the same way. Thank you 👍