Chris C
05/19/2022, 7:44 PMfun main() {
val first = readln()
val second = readln()
println("[$first] [$second]")
}
and this input
1
2
I’m getting this output
[1] []
I would expect
[1] [2]
Or?Igor Kolomiets
05/21/2022, 4:24 PMfun <T> List<T>.headAndTail() = Pair(first(), drop(1))
Does Kotlin offer more idiomatic approach to do this?Ayfri
05/21/2022, 6:05 PMcapitalize()
was removed ? It was so util and the new way to do it is great but looks so raw compared to the methods the String class has, also a method titlecase()
would be great :)Mikhail
05/21/2022, 11:59 PMRegex
constructors ain't even documented..Gianfranco
05/27/2022, 4:37 PMMap<Key,
Set<Value>>
to Map<Value,
Key>
?Ali Khaleqi Yekta
05/28/2022, 6:25 PMMark
05/29/2022, 2:06 AMzip
but with the catch that the second Iterable
contains a count property to indicate the number of items to consume from the first Iterable
? Perhaps a running fold can do this, but I can’t quite get my head around it! At the moment, I can get the desired results by separately maintaining an Iterator
on the first Iterable
, but this doesn’t feel very clean to me.
val list1 = listOf('a', 'b', 'c', 'd', 'e', 'f')
val list2 = listOf(Type2(count = 2), Type2(count = 1), Type2(count = 3))
val expected = listOf(
Pair(listOf('a', 'b'), Type2(count = 2)),
Pair(listOf('c'), Type2(count = 1)),
Pair(listOf('d', 'e', 'f'), Type2(count = 3)),
)
class Type2(val count: Int) {
...
}
Nick
05/29/2022, 7:20 PMstartDate
and an endDate
. I’d like to determine which events overlap so I can place events in a different column. Is there a way to apply some sort of groupBy
function to accomplish a way for me to group them?Mikhail
05/31/2022, 9:58 PMRegex
override equals
?asad.awadia
06/01/2022, 12:49 AMOrhan Tozan
06/17/2022, 1:00 PMminus()
won't do it, since list2 - list1
only shows what list2
has what list1
hasn't.nkiesel
06/17/2022, 7:33 PMEntry
has a toPair()
method, why does Pair
does not have a toEntry()
method?asad.awadia
06/21/2022, 7:21 PMmbonnin
06/22/2022, 3:24 PMSuspiciousCollectionReassignment
inspection. The description says:
fun test() {
var list = listOf(0)
list += 42 // new list is created, variable 'list' still contains only '0'
}
But doing the same thing in playground yields [0, 42]
. What am I missing?David Bieregger
06/22/2022, 3:57 PMtry {
throw Error("Oh no!")
} catch {
console.log("Something bad happened, but don't know what")
}
var result = try throw Error("Oh no!") catch console.log("Something bad happened")
Mikhail
06/26/2022, 8:59 PMJavier
06/26/2022, 10:59 PMDslMarker
markers and picking the nested one?
If I have two function with the same name, the outermost is used
kotlin {
android() // from kotlin
multiplatform {
common()
android() // from kotlin, should be from multiplatform
jvm()
}
}
Andy McGhie
07/04/2022, 11:31 PMKlitos Kyriacou
07/05/2022, 4:32 PMKlitos Kyriacou
07/06/2022, 9:19 AMlog(x, base)
took a default value of E
for base
so as to make log(x)
work just as it does in Java, C, and most other languages, instead of requiring the base to be explicitly passed? It would also form a counterpart of exp(x)
which already implicitly uses a base of E
.Orhan Tozan
07/06/2022, 11:12 AM.filter { }
could have gotten a better name? Everytime I see .filter { }
, my brain has to stand still and figure out if it actually means "filter out" or not. I think .where { }
would have been a more easier name to scan and understand what it doesEric Ou
07/08/2022, 1:40 PMlazy()
, as in lazyNone()
, lazyPublication()
, and lazySyncronized()
, instead of lazy(LazyThreadSafetyMode)
holgerbrandl
07/14/2022, 11:33 AMholgerbrandl
07/14/2022, 11:38 AMIgor Kolomiets
07/14/2022, 9:56 PMfun main() {
var numbers = emptySequence<Int>()
numbers = sequence {
yieldAll(numbers)
yield(1)
}
println(numbers.iterator().next()) // throws StackOverflowError
}
I do realize that such an approach to build up a sequence may seem unnatural, but for my case (I have to implement Kotlin Serialization’s Encoder interface which methods adds/yields next value for the sequence) I haven’t figured out an alternative.Jonathan Ellis
07/22/2022, 2:50 PMMikhail
07/26/2022, 5:56 PMLazyList<T>
that consumes Lazy<T>
and produces T
Mikhail
07/26/2022, 7:54 PMLazy
implement equals
and hashcode
?elect
08/01/2022, 7:57 AMi-2..i+2 in wd.indices
elect
08/01/2022, 8:11 AMaverageBy{ .. }
on iterables, as shortcut instead of map{ }.average()
elect
08/01/2022, 8:11 AMaverageBy{ .. }
on iterables, as shortcut instead of map{ }.average()
Roukanken
08/01/2022, 8:12 AMelect
08/01/2022, 8:13 AMRoukanken
08/01/2022, 8:15 AMelect
08/01/2022, 8:15 AMephemient
08/01/2022, 1:21 PMelect
08/01/2022, 1:22 PMcount{ }