Andrew Gazelka
04/22/2019, 7:41 PMSlackbot
04/23/2019, 1:47 AMferrytan
04/23/2019, 3:49 AM[
{"A",1},
{"A",1},
{"A",1},
{"B",1},
{"C",1},
{"D",1},
{"D",1},
{"A",1},
{"A",1},
{"D",1}
]
I'm aiming to merge the adjacent items and add the integer value for each adjacent items, the end result should transform as this:
Result: [
{"A",3},
{"B",1},
{"C",1},
{"D",2},
{"A",2},
{"D",1}
]
I've searched through basic extensions for Collection, closest i can found is using windowed
with step
1 and size
1, but it seems like i have to loop and map the call multiple times until there are no pairs to get the result i wanted.
Is there any other way to get around this?
I also tried zipWithNext
but it gets tricky if there are more than 2 adjacent items on the listDias
04/23/2019, 9:18 AMAndrew Gazelka
04/23/2019, 2:30 PMribesg
04/23/2019, 3:02 PMfun HttpRequestBuilder.useAuthentication() { ... }
HttpRequestBuilder
is from Ktor client.
I’m trying to use it in another project which has the above one as a dependency:
private suspend fun postUploadFile(successUrl: String): Unit =
<http://http.post|http.post>(successUrl) {
useAuthentication()
}
http
is a Ktor HttpClient
.
IntelliJ IDEA sees the extension, imported it alone without me doing anything, everything works inside IntelliJ. Then I tried to build.
> Task :compileDebugKotlinAndroid FAILED
e: <myFile>.kt: (9, 37): Unresolved reference: useAuthentication
The reference position is in the imports.
What could cause that? I’m posting here because I have no idea where to start. It only seem to happen for this top level extension right now. Maybe it’s a Gradle metadata issue? But then why would IntelliJ see it?tschuchort
04/23/2019, 5:54 PMFoo<*>
in Kotlin equivalent to Foo<?>
in Java?Nezteb
04/23/2019, 7:31 PMval myArg = 1
val myFuncs = listOf(::addOne, ::addTwo, ::addThree)
myArg.someCoolMapFunctions(myFuncs)
There’s a stack overflow answer for Haskell to define this function yourself, but I don’t know what the equivalent Kotlin code would be https://stackoverflow.com/a/47501940/7682196pindab0ter
04/23/2019, 8:11 PM<http://pl.kotl.in|pl.kotl.in>
URL for the Kotlin Playground?Nezteb
04/23/2019, 9:37 PM::funcName
funcName
funcName()
?
The last one I believe is a function invocation, ie () -> Unit
, but the first two confuse me.Nezteb
04/24/2019, 1:06 AMJulien Cayzac
04/24/2019, 1:34 AMwhen
. The require
clause implies element
cannot be a JsonNull
:
fun unbox(element: JsonElement): Any {
require(element !is JsonNull) { "The token contains null values" }
return when (element) { // error: JsonNull case missing
is JsonLiteral -> element.body
is JsonArray -> element.filter { it != JsonNull }.map { unbox(it) }
is JsonObject -> element.content.filterValues { it != JsonNull }.mapValues { unbox(it.value) }
}
}
am414
04/24/2019, 3:04 AMitnoles
04/24/2019, 3:04 AMmarcinmoskala
04/24/2019, 6:50 AMclass A
class B {
fun A.update(i: Int) {}
}
Shawn A
04/24/2019, 3:02 PMfun <R : Any> fromAttr(
prop: KProperty1<T, R>,
transformer: (AttributeValue) -> R
) {
transformers.put(constructorParams.getValue(prop.name), transformer)
}
If I don't supply the type argument I am able to pass a prop
with a different R
than transformer
. For instance:
u.fromAttr(Widget::count) { false }
Where Widget::count
is a Long
. I have to use the form u.fromAttr<Long>(Widget::count) { false }
to get a compiler error. I assume this is happening because of type erasure so Kotlin is inferring R
to be Any
?Nezteb
04/24/2019, 3:44 PMegorand
04/24/2019, 5:40 PMfun Map<K, V>.map()
that returns a Map<K, V>
?jcogilvie
04/24/2019, 6:39 PMKatana
for DI.
Caused by: java.lang.IndexOutOfBoundsException: Insufficient maximum stack size.
at org.jetbrains.org.objectweb.asm.tree.analysis.Frame.push(Frame.java:239)
at org.jetbrains.org.objectweb.asm.tree.analysis.Frame.execute(Frame.java:281)
at org.jetbrains.kotlin.codegen.inline.MethodInliner$Companion$analyzeMethodNodeBeforeInline$analyzer$1$newFrame$1.execute(MethodInliner.kt:1031)
at org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer.analyze(Analyzer.java:187)
arosenb2
04/24/2019, 11:35 PMAndrew Gazelka
04/24/2019, 11:46 PMChannel#send()
but that does not suspend? I know I can use Channel(UNLIMITED)
, but I want to have an interface like a channel that I know will never suspend when I send. The reason for this is I have a function which intakes a channel and outputs data so the inner workings of the function can be recorded (for the purpose of displaying internal, intermediate states within the function).Steve Merrony
04/25/2019, 6:50 AMribesg
04/25/2019, 7:27 AM1.3.31
? Any info about it?vach
04/25/2019, 10:13 AM.java
files it almost doesnt take time... makes sensevach
04/25/2019, 10:14 AMSlackbot
04/25/2019, 5:07 PMrootandy
04/25/2019, 8:19 PMprivate val <T> buffer: List<T> where T : A, T : SomeInterface
Problem: this is not working since T
is not used in "its receiver type" - can somebody help me with the correct syntax for my purpose?Antanas A.
04/26/2019, 11:55 AMjuliocbcotta
04/26/2019, 2:45 PMconst val
instead of val
in a companion object
triggers any compilation/bytecode optimisation ?SrSouza
04/26/2019, 3:07 PM