ianbrandt
01/08/2018, 6:53 AMval bowlingFrames = arrayOf(*1..10)
Also:
val notAnArray = listOf(1, 2, 3)
val list = asList(-1, 0, *notAnArray, 4)
(https://discuss.kotlinlang.org/t/arrays-from-ranges/5216)
Update: Looks like I'm late to the party with this one: https://youtrack.jetbrains.com/issue/KT-12663.Ruckus
01/08/2018, 4:53 PM*(1.9..2.7)
ianbrandt
01/08/2018, 5:23 PMClosedFloatingPointRange
in the stdlib? If someone really wanted to provide an implementation for that, they could do so in an extension function.Ruckus
01/08/2018, 5:26 PMClosedFloatingPointRange
. I can create any sort of range that isn't discrete in nature.ianbrandt
01/08/2018, 5:29 PMspread()
on Iterable
instead.Ruckus
01/08/2018, 5:35 PMRuckus
01/08/2018, 5:39 PMList(n) { ... }
IntArray(n) { ... }
...
They are explicit, unambiguous, and still quite concise,Ruckus
01/08/2018, 5:42 PMianbrandt
01/08/2018, 5:50 PMRuckus
01/08/2018, 5:59 PMianbrandt
01/08/2018, 6:03 PMRuckus
01/08/2018, 6:07 PMeddie
01/08/2018, 6:58 PM(Not to mention overloading the spread operator and allowing it in normal code could cause ambiguities with the multiplication operator).Kotlin already has a unary
-
operator, though. And other languages utilize a unary *
, like C & C++, for example.Ruckus
01/08/2018, 7:01 PM()
). I believe the rest of my arguments are still substantial.ilya.gorbunov
01/09/2018, 5:36 AMWhat would the resulting array be of
arrayOf(*(1.9..2.7))
@Ruckus Floating point ranges are not iterable, so there's no problem with that, it won't just compileRuckus
01/09/2018, 5:43 AMArray(n) { ... }
style.Ruckus
01/09/2018, 5:46 AMeddie
01/10/2018, 5:56 PMeddie
01/10/2018, 6:31 PMRuckus
01/10/2018, 6:35 PMYou've got serious thrill issues dude