aviran
12/28/2019, 8:21 PMSlackbot
12/28/2019, 10:03 PMAnimesh Sahu
12/29/2019, 4:33 AMRuntime.getRuntime().addShutdownHook(object : Thread() {
override fun run() {
server.destroy()
}
})
steenooo
12/29/2019, 1:49 PMtateisu
12/29/2019, 6:33 PMapply {…}
. Why three times slower ?Hullaballoonatic
12/29/2019, 8:43 PMJames Hilliard
12/30/2019, 2:50 AMkotlinOptions.jvmTarget = "1.8"
in my gradle build doesn't work when using java 8?Marc Knaup
12/30/2019, 8:35 AMUnit
.
How should I denote that a parameter takes no value? Unit
or Nothing?
?
That’s relevant in a generic context like Visitor<Result, Data>
where some visitors need no input and hence use Unit
or Nothing?
as Data
.Marc Knaup
12/30/2019, 11:11 AMclass Foo {
@Suppress("TOPLEVEL_TYPEALIASES_ONLY")
typealias Bar = String
}
fun main() {
val hello: Foo.Bar = "hello"
println(hello)
}
Nir Yudovitz
12/30/2019, 1:33 PMmap = mapOf("one" to 1, "two" to "2")
magicWith(map) {
one // 1
two // "2"
}
(I don’t want to create a data class to reduce boilerplates)Animesh Sahu
12/30/2019, 1:52 PMAlejandro Rios
12/30/2019, 7:24 PMDaniel
12/30/2019, 8:33 PMinterface SharedPreferencesBuilder {
fun build(): SharedPreferences
}
I have to denote the type in each implementation since the compiler warns me about the platform typeGyuhyeon
12/31/2019, 8:53 AMdata class Foo(
val bar: Long? = null
)
consider this simple class. Using mybatis, a select
query from a database table is mapped into this class.
I know that mybatis by default uses default noarg constructor, then uses setters to set the value.
However, decompiling the above kotlin class reveals that bar is indeed private final Long
.
When default constructor is called, it seems to me that kotlin will use its synthetic method to automatically set bar
as null.
This would mean that bar cannot be set even with reflection magic.
Does anyone have any idea how val
fields could possibly be mapped correctly from mybatis?jimn
12/31/2019, 9:18 AMvar acc = 0
val order = IntArray(a.size) {
acc += a[it].size
acc
}
is there a more succinct accumulator array creation than this?LastExceed
12/31/2019, 2:41 PMinit
?steenooo
12/31/2019, 7:00 PMShumilin Alexandr
01/01/2020, 9:01 AMLastExceed
01/01/2020, 11:28 AMdata class Node(
val author: String,
val message: String,
val children: List<Node>,
val parent: Node = this
)
why is this
not defined in this context ?
context: Im making a chat client with tree structure instead of linear conversation. Every message is a comment on the message it replies to, except the root node which is a comment on itself (or should i make it nullable? i like to avoid nullability whenever possible)LastExceed
01/01/2020, 2:37 PMfun foo(lastEntry: Entry) {
val myList = mutableListOf<Entry>()
var currentEntry = lastEntry
do {
myList.add(currentEntry)
currentEntry = currentEntry.parent
} while (currentEntry != null)
myList.reverse()
}
how can i simplify this pseudo code so I don't have to perform .reverse()
at the end ?Paul N
01/01/2020, 3:27 PMIs there a build in function to shift the contents of a list right or left ?
e.g. list of 1,2,3 would go to 2,3,1 if I shifted right
Hullaballoonatic
01/01/2020, 6:49 PMLastExceed
01/02/2020, 12:29 PMfun main() {
runBlocking {
val tcpSocketBuilder = aSocket(ActorSelectorManager(<http://Dispatchers.IO|Dispatchers.IO>)).tcp()
val address = InetSocketAddress("127.0.0.1", 2323)
launch {
delay(100)
println("client: connecting to server")
val socket = tcpSocketBuilder.connect(address)
println("client: connected")
println("client: sending data")
val writer = socket.openWriteChannel()
writer.writeStringUtf8("hello world\n")
println("client: data sent")
println("client: done")
}
val serverSocket = tcpSocketBuilder.bind(address)
println("server: waiting for connection")
val client = serverSocket.accept()
println("server: client received")
val reader = client.openReadChannel()
println("server: receiving data")
val message = reader.readUTF8Line(999)
println("server: data received: $message")
println("server: done")
}
}
output:
server: waiting for connection
client: connecting to server
server: client received
client: connected
client: sending data
server: receiving data
client: data sent
client: done
apparently the server gets stuck on receiving the string. why is that and how 2 fix ?Vitali Plagov
01/02/2020, 1:38 PM"one ".trim()
"two ".trim()
"three ".trim()
I would like to improve it with use of scope functions like run
, with
, etc. Can I do with them something like this:
<scope_function> {
"one ",
"two ",
"three ".
}.trim()
?John Douglas
01/02/2020, 4:44 PMAmine
01/02/2020, 5:46 PMError: The 'java' plugin has been applied, but it is not compatible with the Android plugins
Adam Hurwitz
01/02/2020, 6:03 PMKris Wong
01/02/2020, 6:48 PMjava -jar
steenooo
01/02/2020, 8:03 PMwhen
statement?
in fx this situation
enum Foo { FOO, BAR, FOOBAR }
val foo = ...
when(foo) {
FOO -> sayFoo()
BAR -> sayBar()
FOOBAR -> do nothing
}
kyleg
01/02/2020, 9:07 PMinterface Id
inline class BarId(val value: Int): Id
inline class BazId(val value: Int): Id
sealed class Foo<T: Id> {
abstract val id: T
data class Bar(...): Foo<BarId>()
data class Baz(...): Foo<BazId>()
}
fun <T: Foo<U>, U: Id> myFun(entity: T): U = TODO()
Suppose I need to add a function to Foo
that will take an Id param and spit back out a child class (the one that is affiliated with the Id implementation in question). So myBar.changeId
should take BarId
and spit out Bar
. For example.
sealed class Foo<T: Id> {
...
abstract fun <T: Foo<U>, U: Id> changeId(id: U): T
}
I’m sitting here with
data class Bar(...): Foo<BarId>() {
override fun changeId(id: BarId): Bar = TODO()
}
not really knowing what to put for changeId
. Obviously the implementation is going to be changeId(id: BarId): Bar = this(id=id)
but I have to put some generics in the signature somewhere or else compiler/linter tells me this does not match the signature of Foo.changeId, which it is intended to override.