ShootingStar
12/17/2019, 1:05 PMsteenooo
12/17/2019, 3:48 PMSylvain Patenaude
12/17/2019, 8:21 PMEnumerable.Select
to convert from enumeration<type1> to enumeration<type2>? Thanks!Willy Njundong
12/17/2019, 9:11 PMconst myObject = {
someKey: someValue,
someOtherKey: [{foo: "bar"}, {bar: "foo"}]
}
jameswald
12/18/2019, 3:28 AM@file:JvmName("...")
as @Deprecated
?New111
12/18/2019, 8:53 AMProcessBuilder("/bin/sh", "-c",
"java -jar $jarName -f $configName ${args.joinToString(" ")} &")
.start()
how can I redirect stdout of the child to stdout of the parent process (so I could see all the messages together) ? The following code using inheritIO
doesn't work either:
ProcessBuilder("/bin/sh", "-c",
"java -jar $jarName -f $configName ${args.joinToString(" ")} &")
.inheritIO()
.start()
Any clue where the problem is ? Is it somehow related to the fact that the child process writes to log file ?Bruno_
12/18/2019, 11:03 AMWesley Acheson
12/18/2019, 12:23 PMGROUP BY day, status
which would give me a list with the same day more than once and the same status more than once which returned a list of
data class DayStatusCount(val day:LocalDate, val status:Status, val count:Long)
If I wanted to convert to a Map<LocalDate, Map<Status, Long>>
or anythings similar to that. I've been creating mutable maps.
val rawData: MutableMap<LocalDate, Map<Status, Long> = HashMap()
data.forEach {
rawData
.getOrPut(it.day) { HashMap() }
.getOrPut(it.status) { HashMap() }
// More as per step
}
Sorry thats not the real code. but anyway convert from a list with duplicates to nested sets.Joan Colmenero
12/18/2019, 12:50 PMComparator
which returns an Int
but now I need more complex stuff, so I have a method that returns True
or False
depending of a check, is there any way I'd use this method to sort it? Is getting Foo1
Foo2
as a parameter and then do the comparation.Slackbot
12/18/2019, 2:22 PMLauritz Hilsøe
12/18/2019, 2:46 PM<?xml version="1.0" encoding="UTF-8">
<provider version="1.0">
<update id="12313">
<event name="hello" created_at="2019-12-14" />
<event name="world" created_at="2019-12-16" />
<country where="us" created_at="2019-15-16" />
</update>
</provider>
Basically want to end up with a class containing ProviderUpdate(id: String, updates: List<Update>)
where Update
is either an interface, class, sealed class or something, that can either be Event
or Country
or etcSylvain Patenaude
12/18/2019, 4:19 PMsandjelkovic
12/18/2019, 6:04 PMlateinit var
not allowed for inline classes that wrap types that otherwise can be lateinit
-ed?
For example:
inline class Id(val value: String)
can’t be used as
private lateinit var id: Id
and is there a workaround that is not a nullable field or a data class?elect
12/18/2019, 7:54 PMinline fun defaultCheck(result: VkResult) = result.check()
fun bar(check: (VkResult) -> Unit = ::defaultCheck) {
check(..)
}
would there be any allocation regarding passing the lambda to bar
?Dariusz Kuc
12/18/2019, 8:56 PMjavaClass.classLoader.getResource("myFile").readBytes() // 198
File("myFile").inputStream().readBytes() // 184
If I'm reading input stream from a resource (which I have to in deployed app) I get some extra bytes that I do not get if I read the file directly. Any ideas?Joffrey
12/19/2019, 10:24 AMfun List<Pair<K,V>>.toMap()
drops duplicate entries without providing a way to merge them. Is there a stdlib function that can do this?
I often need this when dealing with maps containing quantities. I implement it this way:
fun <K, V> List<Pair<K, V>>.toMap(combine: (V, V) -> V?): Map<K, V> {
val result = mutableMapOf<K, V>()
for ((k, v) in this) {
result.merge(k, v, combine)
}
return result
}
Another one I'm missing is merging 2 maps provided a function to recombine the values of keys that are present in both maps.Ray Eldath
12/19/2019, 11:58 AMlateinit val
which is immutable after the initialization...? in my practice actually my lateinit
is always for this immutable occasion...
A friend of mine said that in the early version of Kotlin there is something like that, but then it's withdrawn.
BTW, in KotlinConf 2018 Closing Panel many a speaker regarded lateinit
as their most annoying Kotlin feature, and seems lots of audience agreed the opinion. I am wondering if this is because of the problem mentioned above...Anders Mikkelsen
12/19/2019, 12:09 PMandyg
12/19/2019, 12:11 PMvar id:Int = 0
boilerplate, because once established, all values should be immutable, and no instance should ever have id = 0) Thanks 🙂jeggy
12/19/2019, 2:34 PMinfix operator fun contains(option: Option): Boolean
I would like to be able to write both cases if (data contains MyOption)
and if (data !contains MyOption)
Andreas Unterweger
12/19/2019, 3:27 PMinterface RequestAuth {
fun header(): Pair<String, String>
}
val instance = object : RequestAuth {
override fun header(): Pair<String, String> = "name" to "value"
}
cant this be done more more concisely? sth like
val instance = object : RequestAuth { "name" to "value" }
jmfayard
12/19/2019, 3:49 PMSlackbot
12/19/2019, 4:52 PMJohn
12/19/2019, 5:58 PMsealed class Source(
@Json(name = "value")
val value: String,
@Json(name = "value2")
val value2: Boolean
) {
object Source1: Source
object Source2: Source
}
Jannis
12/19/2019, 6:19 PMgenerateSequence(0) { it + 1 }.take(100000).fold(emptySequence<Int>()) { acc, v ->
acc + v
}.first() => stackoverflows
Also this works fine:
generateSequence(0) { it + 1 }.take(100000).fold(emptySequence<Int>()) { acc, v ->
sequenceOf(v) + acc
}.first() => works fine
Will Nixon
12/19/2019, 9:18 PMkpgalligan
12/19/2019, 9:25 PMJérôme Gully
12/20/2019, 4:08 PMrepositories {
mavenCentral()
maven { url = uri("<https://dl.bintray.com/kotlin/kotlin-dev>") }
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlinx:kotlinx-cli:0.2.0-dev-7"
}
fun main(args: Array<String>) {
val parser = ArgParser() // ArgParser not found
}
Sylvain Patenaude
12/20/2019, 9:15 PMOfir Bar
12/21/2019, 1:31 PMval customClickSpan = object : ClickableSpan() {
override fun onClick(widget: View) {
Toast.makeText(widget.context, "Click worked!", Toast.LENGTH_SHORT).show()
}
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
ds.color = Color.RED
ds.isUnderlineText = true
}
}
And then I pass it to my method:
fun setLinksWithinText(stringResource : CharSequence, clickListener : ClickableSpan) : SpannableString {
val stringResourceSpanned = stringResource as SpannedString
val annotations = stringResourceSpanned.getSpans(0, stringResourceSpanned.length, android.text.Annotation::class.java)
val spannableString = SpannableString(stringResourceSpanned)
for (annotation in annotations) {
// look for the span with the key "font"
if (annotation.key == "text_type") {
val textType = annotation.value
if (textType == "link") {
spannableString.setSpan(
clickListener,
stringResourceSpanned.getSpanStart(annotation),
stringResourceSpanned.getSpanEnd(annotation),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
}
}
return spannableString
}
Ofir Bar
12/21/2019, 1:31 PMval customClickSpan = object : ClickableSpan() {
override fun onClick(widget: View) {
Toast.makeText(widget.context, "Click worked!", Toast.LENGTH_SHORT).show()
}
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
ds.color = Color.RED
ds.isUnderlineText = true
}
}
And then I pass it to my method:
fun setLinksWithinText(stringResource : CharSequence, clickListener : ClickableSpan) : SpannableString {
val stringResourceSpanned = stringResource as SpannedString
val annotations = stringResourceSpanned.getSpans(0, stringResourceSpanned.length, android.text.Annotation::class.java)
val spannableString = SpannableString(stringResourceSpanned)
for (annotation in annotations) {
// look for the span with the key "font"
if (annotation.key == "text_type") {
val textType = annotation.value
if (textType == "link") {
spannableString.setSpan(
clickListener,
stringResourceSpanned.getSpanStart(annotation),
stringResourceSpanned.getSpanEnd(annotation),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
}
}
return spannableString
}
Siyamed
12/21/2019, 1:50 PM