Stefan Peterson
03/05/2019, 6:32 PMid
. These `id`s are unique. I know I can use groupBy
to create a map but that results in Map<Long, List<*>>
when I would much rather have Map<Long, *>
. Is there a nice idiomatic way to do this in K?Stefan Peterson
03/05/2019, 6:36 PMmarstran
03/05/2019, 7:48 PMprintln(-0.0 == 0.0) // true
println("${-0.0 == 0.0}") // false
LeoColman
03/05/2019, 7:54 PMfun foo(fn: () -> Unit) {}
suspend fun foo(fn: suspend () -> Unit) {}
but in the same packageLeoColman
03/05/2019, 8:42 PMfun foo<A>(a: A) {}
fun foo<A, B>(a: A, b: B){}
fun foo<A,B,C>(a: A, b: B, c: C) { }
...
until foo<125> types
kieran
03/05/2019, 11:19 PMTloru
03/06/2019, 1:02 AMxenoterracide
03/06/2019, 5:40 AMjw
03/06/2019, 5:43 AMArray(bytes.size) { bytes[it] }
to box. i don't think there's built-in array boxing functionsarekolek
03/06/2019, 12:03 PMinit
block? If there’s more than one constructor, you can’t access any arguments? Or is it something different?morbidmerve
03/06/2019, 12:20 PMHexa
03/06/2019, 1:26 PMursus
03/06/2019, 2:51 PMstreetsofboston
03/06/2019, 2:53 PMursus
03/06/2019, 2:56 PMYossi Saiada
03/06/2019, 3:09 PM(0.0).equals(-0.0) // false
(0.0) == (-0.0) // true
Does anyone can explain it?LG
03/06/2019, 4:47 PMmapValues
?amansinghal
03/06/2019, 5:09 PMLeoColman
03/06/2019, 8:10 PMhi
also display : String
(hint, not typed)?Luke
03/06/2019, 8:11 PMbbaldino
03/06/2019, 8:17 PMoriginalList = listOf(1, 2, 3, 4, 5, 10, 11, 14, 15, 19, 22);
chunks = originalList.chunkMaxDifference(5);
chunks = ((1, 2, 3, 4, 5), (10, 11, 14, 15), (19, 22))
i came up with this, but i wonder if there’s a better way:
fun List<Int>.chunkMaxDifference(maxDifference: Int): List<List<Int>> {
val chunks = mutableListOf<List<Int>>()
if (this.isEmpty()) {
return chunks
}
var currentChunk = mutableListOf<Int>(first())
chunks.add(currentChunk)
// Ignore the first value which we already put in the current chunk
subList(1, size).forEach {
if (it - currentChunk.first() > maxDifference) {
currentChunk = mutableListOf(it)
chunks.add(currentChunk)
} else {
currentChunk.add(it)
}
}
return chunks
}
vinay
03/07/2019, 6:31 AMjakub.dyszkiewicz
03/07/2019, 3:04 PMlist + element
copies the whole list and adds an element. Are there any plan to create truly immutable lists so that plus operator uses old list with pointer to new element?Marc Knaup
03/07/2019, 4:18 PMclass Test(val a: Int = 1, val b: Int = 2, val c: Int = 3)
fun test() {
var a: Int? = null
var b: Int? = null
var c: Int? = null
if (someCondition) a = somethingNonNull
if (someCondition) b = somethingNonNull
if (someCondition) c = somethingNonNull
Test(
a = a ?: howToUseDefaultValue, // ??
b = b ?: howToUseDefaultValue, // ??
c = c ?: howToUseDefaultValue // ??
)
}
ursus
03/07/2019, 5:36 PM@Throws
annotation worth anything in practise?Hexa
03/07/2019, 7:20 PMkinesisEvent.records.asSequence()
before calling foreach in this example: // event: List<KinesisEvent.KinesisEventRecord>
event.records.forEach {
try {
val putRecordsRequest = PutRecordsRequest()
putRecordsRequest.streamName = "test-stream"
val putRecordsRequestEntryList = ArrayList<PutRecordsRequestEntry>()
for (i in 0..499) {
val putRecordsRequestEntry = PutRecordsRequestEntry()
putRecordsRequestEntry.data = it.kinesis.data
putRecordsRequestEntry.partitionKey = it.kinesis.partitionKey
putRecordsRequestEntryList.add(putRecordsRequestEntry)
}
putRecordsRequest.setRecords(putRecordsRequestEntryList)
val putRecordsResult = kinesisClient.putRecords(putRecordsRequest)
} catch (e: InterruptedException) {
//log error here
}
Rafa
03/07/2019, 8:29 PMcomponent
extension properties on a collection, but with a data class we generate componentN
up until (what i'm assuming, couldn't find documentation on it) we reach the limit of functions that can be created in a class on the JVM?pakoito
03/08/2019, 12:19 AMAndrew Gazelka
03/08/2019, 12:27 AMProblem<I,O>
... I
is input, O
is output and implements fun solve(input: I): O
- each problem extends Problem<O>
where input is provided in constructor
- each problem is a top-level function
- each problem is a HOF