https://kotlinlang.org logo
Title
m

mersan

11/19/2018, 5:55 PM
is there a way to create a function to look like this
doSomething{
  "a"
  "b"
  "c"
}
and i can read the input as an list or array of items?
m

Mike

11/19/2018, 5:56 PM
perhaps
fun doSomething(vararg values:String)
👍 1
s

Shawn

11/19/2018, 5:57 PM
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

Jake

11/19/2018, 5:57 PM
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

Shawn

11/19/2018, 5:57 PM
that’d look like
doSomething {
  +"a"
  +"b"
  +"c"
}
unless you really mean
doSomething(
    "a",
    "b",
    "c"
)
m

mersan

11/19/2018, 5:58 PM
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

Shawn

11/19/2018, 6:00 PM
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

mersan

11/19/2018, 6:01 PM
Ok thanks, ill give it another try if there is a work around this somehow
s

Shawn

11/19/2018, 6:02 PM
a workaround? what are you even trying to do?
☝️ 3
e

edwinRNDR

11/19/2018, 6:49 PM
likely make a DSL without the noise of commas or + operators
👍 1
m

mersan

11/19/2018, 8:05 PM
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

Nikky

11/20/2018, 2:05 AM
seems like vararg Strings would be sensible there