is there a way to create a function to look like t...
# announcements
m
is there a way to create a function to look like this
Copy code
doSomething{
  "a"
  "b"
  "c"
}
and i can read the input as an list or array of items?
m
perhaps
fun doSomething(vararg values:String)
👍 1
s
assuming you really want a lambda/builder kinda deal, I think the closest you can get is defining
operator fun unaryPlus
on your builder object
j
vararg
makes the parameter optionally an array of the defined type. Not to say that it's made optional. But you can include
"s"
or an
arrayOf["s","e","c"...]
s
that’d look like
Copy code
doSomething {
  +"a"
  +"b"
  +"c"
}
unless you really mean
Copy code
doSomething(
    "a",
    "b",
    "c"
)
m
i was looking for a way the return or new line means a new item/input
vararg will need the input to be split with commas
Yes @Shawn I mean that if its possible
s
that’s not really how Kotlin’s grammar works for the most part. There are some proposals for comma omission in certain contexts, but nothing’s been formally accepted or announced yet afaik
m
Ok thanks, ill give it another try if there is a work around this somehow
s
a workaround? what are you even trying to do?
☝️ 3
e
likely make a DSL without the noise of commas or + operators
👍 1
m
I was trying to achieve a function you pass to all the dependencies in gradle as strings and it will convert them into dependencies
n
seems like vararg Strings would be sensible there