when writing a Kotlin DSL, is there a better way o...
# announcements
k
when writing a Kotlin DSL, is there a better way of having a lambda accept a list of enums than using the "plus" overloading technique like this? With the unary plus technique, you end up w/ DSL code that looks like: authMethod { +PIN +CHIP } but it'd be nice to remove the '+' prefix
s
what exactly would you rather this look like
like you can’t really get rid of the
+
- you could replace it with some other operator, but you can’t really have a bare list here
maybe if you wrote an overload that took
() -> List<AllowedMethodType>
so it could look like
Copy code
authMethod { listOf(
  PIN,
  CHIP
)}
but I don’t know if that’s much better
k
Wanted a bare list. Yep, tried the listof already. I have an assignment method too so you can pass a list in.
l
You can provide a lambda receiver that has
operator fun invoke
for the target types so you use
()
instead