Is there a way to make an operator function that a...
# general-advice
c
Is there a way to make an operator function that accepts varargs? For DSL purposes, obviously. Specifically: something like
"foo" in ("bar", "baz", "qux")
instead of
"foo" in listOf("bar, "baz", "qux")
so it doesn't read as cluttered. This one might actually be impossible since it would require
fun (vararg T).contains
, but it would be nice to do
myList -= "x", "y", "z"
c
It's not possible for
in
because it can't be overridden directly (as you mentioned, it's
contains
), but it's possible with all the other ones that take the argument as a regular argument
it would be nice to do
myList -= "x", "y", "z"
That would be very ambiguous:
Copy code
foo(myList -= "x", "y", "z")