any chance we can get a `vararg` that means one or...
# language-proposals
g
any chance we can get a
vararg
that means one or more rather than zero or more?
☝️ 1
i
I filed an issue for this: https://youtrack.jetbrains.com/issue/KT-57266/One-or-more-varags. I believe it would pair nicely with non-empty collections (https://youtrack.jetbrains.com/issue/KT-21217/Non-empty-collections) for robust, compile-time checked domain modeling of one-or-more scenarios.
e
perhaps this should depend on what happens in https://youtrack.jetbrains.com/issue/KT-43871/Collection-literals. using arrays to represent varargs is always going to require runtime checking of one-or-more. if you could instead write
Copy code
fun f(args: NonEmptyList<T>)
f([1, 2, 3])
I think it would be a better option
i
Maybe
varargs+
could be represented by a new
NonEmptyArray
type, but I agree that collection literals would be related and should be considered.
g
how far can a contract get us here?
e
vararg+
wants to constrain callers to provide at least one argument contracts do not constraint callers. they declare certain guarantees about the callee's behavior to the caller
👍 1