David Gracia
08/30/2021, 8:58 PMxxfast
08/31/2021, 12:27 AMval actual = listOf("a","b","c","d")
val expected = listOf("ab","bc","cd")
Rob Elliot
09/14/2021, 9:09 AMfun <T, R> T.runCatching(block: T.() -> R): Result<R>
- it catches Throwable
, and hence Error
, including things you almost certainly don’t want to catch like OutOfMemoryError
. It also makes no attempt to propagate InterruptedException
(or reset the interrupted status of the Thread when catching it).
Am I missing something? Or just woefully out of date in my JVM exception handling?edrd
09/16/2021, 8:34 PMString.prepend(value: String)
in the stdlib? I need it quite often and .let { "prefix$it" }
doesn't express intent so well.xxfast
09/20/2021, 1:11 AMval actual = listOf(
Item(type = A, value = 1),
Item(type = B, value = 2),
Item(type = B, value = 3)
)
val expect = mapOf(
A to listOf(Item(type = A, value = 1)),
B to listOf(Item(type = B, value = 2), Item(type = B, value = 3)),
C to emptyList()
)
dimsuz
09/20/2021, 1:51 PMdata class Value(val foo: Foo?)
and I do if (value.foo != null) foo.bar() else doStuff()
, there's an error "smart cast is impossible".
But if I know that a) it's val b) no multithreading is used, can I "smarten" the compiler? Perhaps by adding some contract
somewhere? Is there a YouTrack issue along these lines maybe?darkmoon_uk
09/22/2021, 2:56 AMthis talk▾
lazy
(and possible other Property Delegation) - the foundation of their argument appears to be that use of reflection in property delegation is too costly for most use cases. Unfortunately they don't give any examples of where the 'tipping point' of complexity lies; where lazy
does become worth it.
This has put my team off from using lazy even for cases where moderately complex objects are being created.
I'm suspect of two things in this talk: firstly their poor choice of example - obviously it's going to be inefficient to use this to allocate an Int
, but what about smaller-to-moderately sized classes? No benchmarks provided or discussion of initial lazy
cost vs. subsequent lazy
where presumably some aspects of any reflection would have become cached.
Thoughts?PHondogo
09/22/2021, 7:44 AMHullaballoonatic
09/26/2021, 11:03 PMList
have chunked()
but DoubleArray
does not?Orhan Tozan
09/27/2021, 1:41 PMvalue class UserId(private val value: Int)
fun sendUser1(userId: UserId) = ...
fun sendUser2(userId: Int) = ...
// Compiler error: required: UserId, found: Int. Makes sense because an Int isn't always a UserId.
sendUser1(1)
// Compiler error: required: Int, found: UserId. Does not make sense because a UserId is always an Int.
sendUser2(UserId(1))
Why doesn't the compiler see that type UserId is of type Int? It makes it harder for a project to adopt value classes if the new types aren't compatible with it's super typenatario1
09/28/2021, 8:00 AM@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // false warning, extension takes precedence in some cases
Does anyone know in which cases the extension takes precedence? This one is Collection<T>.containsAll(elements: Collection<T>)
for instance.elect
09/28/2021, 12:59 PMIntRange
and similars have methods to easily extract collections. ClosedRange
instead no.. this is a pitymikehearn
10/04/2021, 4:48 PMjava.io.File
instead of java.nio.file.Path
? I assume this is to do with the legacy Java 1.6 support but it's quite awkward for programs that want to benefit from the NIO features like in-memory file systems, etc.mikehearn
10/04/2021, 4:48 PMjava.nio.file.Path
and then leave the current methods as forwarders that convert the File to a Path.darkmoon_uk
10/07/2021, 1:26 AM{ it }
where for a single parameter lambda that merely pipes-through its input value?Tomasz Krakowiak
10/10/2021, 3:01 PMColm Murphy
10/11/2021, 11:03 AMshl
or shr
infix functions. Is this intentional or not?Javier
10/12/2021, 10:50 AMjimn
10/12/2021, 3:13 PMInstant
ctor, and serialization, we need 12 bytes, a long for ms and int for nanos.
The kotlin Duration
analog class only appears to support at best a Long or Double, neither which supports the same resolution. Instead of a break between Java's Date, DateTime, and Instant classes which supports DateTimes with nanosecond backingstores, Duration apparently presumes to do all three and for events on astronomical scales of time resolution appears to force the coder to box a relative 64 bit expanse of measurement for the non-jvm stdlib.
to my understanding BigInteger math is a sliding set of 32 bit Int operations going up and down to MAXINT resolution and is claimed to be faster in the C2 on intel than native wide instructions in some cases.
Is Duration with a promotion option to BigInteger backingstore reasonable?
The solution would address
a) usecases that want higher res, and
b) a sideload BitSet/BigInt serialization option that can match impedences with e.g. Instance and other DateTime libraries which don't all apparently assume 64 bits and only 64 bits.Joffrey
10/13/2021, 2:56 PMmaxBy
and minBy
going to be un-deprecated in 1.6 with a new strict behaviour? Or is it planned for a later version?elect
10/13/2021, 6:01 PMMap<K, V>
the getOrElse
by passing as argument the key which wasn't found?
public inline fun <K, V> Map<K, V>.getOrElse(key: K, defaultValue: () -> V): V
to
public inline fun <K, V> Map<K, V>.getOrElse(key: K, defaultValue: (V) -> V): V
My use case is to search for the same key somewhere elsesmichel17
10/15/2021, 1:09 PMSequence.takeWhile
? E.g. one of these:
fun <T>Sequence<T>.takeThenWhile(count: Int, predicate: (T) -> Boolean): Sequence<T> {
var i = 0
return this.takeWhile{ i < count || predicate(it) }.onEach { i++ }
}
fun <T>Sequence<T>.takeWhileIndexed(predicate: (Int, T) -> Boolean): Sequence<T> {
var i = 0
return takeWhile { predicate(i, it) }.onEach { i++ }
}
Both take
and takeWhile
could be implemented in terms of this function
fun <T>Sequence<T>.take(count: Int) = takeThenWhile(count) { false }
fun <T>Sequence<T>.takeWhile(predicate: (T) -> Boolean) = takeThenWhile(0, predicate)
fun <T>Sequence<T>.take(count: Int) = takeWhileIndexed { i, _ -> i < count }
fun <T>Sequence<T>.takeWhile(predicate: (T) -> Boolean) = takeWhileIndexed { _, t -> predicate(t) }
rocketraman
10/18/2021, 6:31 PMpartition
only supports two outputs. What about adding something like this to the stdlib?
/**
* Similar to the stdlib partition method, but supports an arbitrary number of output lists. The number
* of outputs must be known in advance.
*/
@Throws(IndexOutOfBoundsException::class)
fun <T> List<T>.partitionInto(size: Int, predicate: (T) -> Int): List<List<T>> {
val lists = listOf(*(0.until(size).map { mutableListOf<T>() }.toTypedArray()))
for (element in this) {
val index = predicate(element)
lists[index].add(element)
}
return lists
}
groostav
10/18/2021, 8:14 PMinline class
to simplify java's`compareTo` function? I was thinking that an inline class
that's wrapping the results would be handy and do a lot for readability.
If not, can we typealias ComparisonResult = Int
and put some docs there?
I feel like kotlin can do a lot to add sugar and/or lipstick to this pig in java.natpryce
10/22/2021, 7:23 AMList::chunked
doesn’t do what I want, nor does List::windowed
.
E.g. if I have a list, x = [“a”, “b”, “C”, “d”, “E”, “F”, “g”] and I want to split it into sublists where the case is the same within the sublist, I could pass in a predicate to this function something like…
x.split { x, b -> a.isUpperCase() != b.isUpperCase() }
giving me:
[["a", "b"], ["C"], ["d"], ["E", "F"], ["g"]]
I often need this operation, but always end up writing it with imperative code. Is there something in the stdlib I’m missing.mazorius
10/22/2021, 1:01 PM.capitalize()
is be replaced by .replaceFirstChar()
but the latter one is not shown in my IDE? I only got replaceFirst
Ruckus
10/23/2021, 12:11 AMenumValues<T>(): Array<T>
and enumValueOf<T>(name: String): T
for enums. It would be nice if there was also enumValueAt<T>(ordinal: Int): T
. It's pretty easy to work around with enumValues()[ordinal]
, so not a huge deal, but it feels a bit clunky.
Another nice to have for would be something like enumSize<T>(): Int
. Again, easy to work around with enumValues().size
, but same argument as above.holgerbrandl
11/01/2021, 7:39 PMceil()
not an extension on Double?maxmello
11/02/2021, 4:56 PMjoinToString
has truncated: CharSequence = "..."
as an optional parameter. It would be nice if String.take(n: Int)
could have the same optional parameter that is appended in case n
is smaller than the length of the String. Maybe it could also be a different method name, as this would be more a use case for logging/displaying a string similar to joinToString, rather than “working on a string” by using substring for maybe some logical operation on the string. It could be something like abbreviate
or maybe cut
Ansh Tyagi
11/04/2021, 5:30 PMAnsh Tyagi
11/04/2021, 5:30 PMBig Chungus
11/04/2021, 5:32 PMAnsh Tyagi
11/04/2021, 5:36 PMBig Chungus
11/04/2021, 5:37 PMAnsh Tyagi
11/04/2021, 5:39 PMBig Chungus
11/04/2021, 5:39 PMAnsh Tyagi
11/04/2021, 7:25 PMephemient
11/04/2021, 8:07 PMexec {}
or an Exec
task instead of ProcessBuilder
3. :not-kotlin: