miha-x64
06/06/2020, 10:18 PMinline fun CharSequence.forEachCodePoint(
start: Int = 0, end: Int = length,
action: (index: Int, codePoint: Int) -> Unit
) {
var i = start
var codePoint: Int
while (i < end) {
codePoint = Character.codePointAt(this, i);
action(i, codePoint)
i += Character.charCount(codePoint)
}
}
LeoColman
06/07/2020, 9:01 PMbod
06/11/2020, 5:01 PMrrva
06/24/2020, 1:57 PMrrva
06/24/2020, 2:56 PMfilter
or filterNot
?rrva
06/25/2020, 7:11 AM@OptIn(ExperimentalTime::class)
class DateTimeSource(val time: OffsetDateTime) : AbstractLongTimeSource(unit = DurationUnit.MILLISECONDS), TimeSource {
override fun read(): Long {
return time.toInstant().toEpochMilli()
}
}
Hullaballoonatic
07/05/2020, 9:33 PMfun <C : Comparable<C>> C.coerceAtMost(maxValue: C) = if (this > maxValue) maxValue else this
fun <C : Comparable<C>> C.coerceAtLeast(minValue: C) = if (this < minValue) minValue else this
fun <C : Comparable<C>> C.coerceIn(minValue: C, maxValue: C) = coerceAtLeast(minValue).coerceAtMost(maxValue)
Also
fun <C : Comparable<C>> min(vararg elements: C): C
fun <C : Comparable<C>> max(vararg elements: C): C
I'm a bit surprised these methods aren't part of stdlib of any languages i know of. Is there a reason I haven't considered?Jamy
07/06/2020, 11:55 PMval a = b?.c.toString()
where b == null
results a != null
since in this case a == "null"
. So to get what I want, I have to write val a = b?.c?.toString()
. It’s not a problem, I just don’t understand the purpose.louiscad
07/08/2020, 12:15 PMfun List<E>.subListAfterFirst(element: E): List<E>
fun List<E>.subListAfterLast(element: E): List<E>
They could also take a predicate instead of an element.
Maybe there's already a good alternative that I didn't think of or found?bbaldino
07/10/2020, 10:28 PMKType
(of the enum) and a string (of the enum value) ?diego-gomez-olvera
07/17/2020, 11:18 AMpublic fun <T> MutableList<T>.removeAll(predicate: (T) -> Boolean): Boolean = filterInPlace(predicate, true)
private fun <T> MutableList<T>.filterInPlace(predicate: (T) -> Boolean, predicateResultToRemove: Boolean): Boolean {
if (this !is RandomAccess)
return (this as MutableIterable<T>).filterInPlace(predicate, predicateResultToRemove)
var writeIndex: Int = 0
for (readIndex in 0..lastIndex) {
val element = this[readIndex]
...
if (writeIndex != readIndex)
this[writeIndex] = element
...
}
It seems CopyOnWriteArrayList.removeAll
does not copy on write but mutates in place insteadnkiesel
07/17/2020, 8:07 PMfun Iterable<String>.sortedWith(collator: Collator) = this.map { collator.getCollationKey(it) }.sorted().map { it.sourceString }
Daniele B
08/08/2020, 8:02 PMnatpryce
08/09/2020, 8:40 AMMarc Knaup
08/09/2020, 1:49 PMFlow.toList()
closes the Flow but Stream.toList()
doesn’t close the Stream.
Is that inconsistency intentional?Daniele B
08/10/2020, 4:06 PMval myString = "%.1f".format(myFloat)
it tells me that the function format
doesn’t exist?Matteo Mirk
08/13/2020, 8:56 AMjava.text.NumberFormat
in Kotlin multi-platform stdlib? I can’t seem to find any…Fleshgrinder
08/15/2020, 3:56 PMbuildList
and friends are still experimental in Kotlin 1.4?rrva
08/17/2020, 8:36 AMEsa
08/20/2020, 11:36 AMIterable<T>
that has been very useful to me personally, and I wish to make a contribution to the stdlib with those. 🙂 I read through this link and was suggested to make my plans known to #kontributors, however they sent me here. So here's what the functions are basically:
list.validatedFold
- this is a function that iterates through the elements of an ordered list, and verifies that elements n
and n+1
pass some validation function. returns true if all elements pass, or false on the first element that does not pass (early return).
list.flatMapIndexedNotNull
- essentially what the name says, it was relevant for me in one case and I didn't find it in the stdlib.Daniele B
09/03/2020, 11:00 AMfun main() {
val number = 0.001 * 0.001
println(number.toString())
// prints 1.0E-6
}
How can I make it print “0.00001” ?diego-gomez-olvera
09/15/2020, 10:40 AMReader
extensions do not use @JvmThrows
https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/jvm/src/kotlin/io/ReadWrite.kt#L120elect
09/24/2020, 8:53 AMString.getOrNul(index: Int): Char
where nul
is \u0000
Daniele B
10/07/2020, 6:32 PMrnett
10/15/2020, 3:40 AMorg.jetbrains.kotlin.utils.addToStdlib
in the compiler artifact. Are these things that will be added to the stdlib soon? Because several (especially cast
and safeAs
, for me) are quire nicespand
10/22/2020, 6:54 AMspand
10/23/2020, 11:28 AMMap<K, V>.getOrElse
? on ie.
mapOf("1" to null).getOrElse("1") { error("missing") }
Will throw an error yet containsKey("1")
return true
. The docs says:
... or the result of the [defaultValue] function if there was no entry for the given key.
There is an internal getOrElseNullable
that would fix it but I assume it was not chosen for a reasonMark
10/26/2020, 6:38 AM() -> Item
lambdas and I want to map it like map { it() }
. Is it possible to write this using a function reference? I was guessing something like map((()->Item)::invoke)
mbonnin
10/30/2020, 2:12 PMMiSikora
11/01/2020, 1:53 PMpublic fun <T : Enum<T>> enumValues(enumClass: KClass<T>): Array<T>
MiSikora
11/01/2020, 1:53 PMpublic fun <T : Enum<T>> enumValues(enumClass: KClass<T>): Array<T>
miha-x64
11/01/2020, 1:59 PMMiSikora
11/01/2020, 2:00 PMKClass