Mark Buikema
06/23/2020, 1:59 PMdata class Hotel(
val id: String,
val openStatus: OpenStatus //OpenStatus is an enum with values OPEN, PREORDER, CLOSED
val favorite: Boolean
val sortingValue: Int
)
Now I have a list of hotels. I want to sort the list in a way that it results in this:
Open/preorder section (openStatus == OPEN || openStatus == PREORDER)
Favorites
Open
Sorted by sortingvalue
Preorder
Sorted by sortingvalue
Non-favorites
Open
Sorted by sortingvalue
Preorder
Sorted by sortingvalue
Closed section (openStatus == CLOSED)
Favorites
Sorted by sortingvalue
Non-favorites
Sorted by sortingvalue
What would be the best way to achieve this sorting behavior?Rob Murdock
06/23/2020, 3:15 PMToddobryan
06/23/2020, 5:25 PMkotlinc
on code that references Scala 2.12.11's List
(or any other class that references TraversableOnce
) causes the compiler to crash. A minimal example is:
import scala.collection.JavaConverters.asScalaBuffer
fun main() {
val kotlinList: List<String> = listOf("abc", "def", "ghi")
val scalaList = asScalaBuffer(kotlinList).toList
println(scalaList)
}
This works fine with Scala 2.12.10, but won’t even compile with Scala 2.12.11. The difference seems to be https://github.com/scala/scala/blob/v2.12.10/src/library/scala/collection/TraversableOnce.scala#L102 vs https://github.com/scala/scala/blob/v2.12.11/src/library/scala/collection/TraversableOnce.scala#L117 where they introduced a reverser
object that is confusing Kotlinc’s bytecode analysis.Vinicius Araujo
06/23/2020, 6:57 PMthis
? This wont work:
val Delegado.number: Int by lazy {
println("Executed")
this.id + 1
}
Joakim Tengstrand
06/23/2020, 7:56 PM<https://jitinsharma.in/posts/parsing-kotlin-using-code-kotlin/>
Now I have converted that Kotlin code to Clojure, but when I try to access this field:
public final val importList: org.jetbrains.kotlin.psi.KtImportList?
Living in this class:
org.jetbrains.kotlin.psi.KtFile
In this library:
org.jetbrains.kotlin/kotlin-compiler-embeddable "1.3.72"
The problem is that this field is a val and that it's not annotated with @JvmField (that is my guess) and therefore I don't know how to access it. Can I use reflection or is there another way?Twferrell
06/24/2020, 12:43 AMlmj0011
06/24/2020, 12:59 AMbuild.gradle
?
After reading https://www.raywenderlich.com/2780058-domain-specific-languages-in-kotlin-getting-started it's still not clicking.Ko Bokh
06/24/2020, 11:01 AMxii
06/24/2020, 11:58 AMfooList.filter { if (state.contains('A') it.isA() else false || if (state.contains('B') it.isB() else false }
but it looks uglyRobert Jaros
06/24/2020, 1:22 PMinternal
field be visible from the test code? It works when I run compile and test tasks from Gradle, but when I work with code in IntelliJ it is marked as an error.kushalp
06/24/2020, 1:29 PMbuild.gradle.kts
files. Bonus points if it is configured using an entirely separate sourceSet
Philipp Mayer
06/24/2020, 1:37 PMclass Dto(val name: String, val age: Int, val somethingElse: String) {
var signedKey = ""
fun encrypt(shaSign: String): String {
/*do something with all constructor fields*/
return "encryptedString"
}
}
the function encrypt(shaSign: String)
returns an encrypted string by hashing the fields name
, age
and somethingElse
.
I basically just want to set the field signedKey
with the output of that operation.
val dto = Dto("John", 36, "something else")
dto.signedKey = dto.encrypt("someShaKey")
Ofc I could do it like that, but that is really not a good way. I thought a bout a distinct setter which takes a parameter (some sign), executes encrypt
and places the returned value as signedKey
.
How could I achieve that? Thanks ahead!Gopal S Akshintala
06/25/2020, 4:02 AMuser
06/25/2020, 9:23 AMIfvwm
06/25/2020, 9:53 AMbod
06/25/2020, 10:00 AMby
)?
var parameter: Parameter
set(value) {
delegate.parameter = value
}
get() = delegate.parameter
iex
06/25/2020, 11:02 AMSmart cast to 'UserInput.Some' is impossible, because 'alert.earliestSymptomTime' is a public API property declared in different modulecode:
when (alert.earliestSymptomTime) {
is UserInput.Some -> alert.earliestSymptomTime.value.value
is UserInput.None -> null
}
Why does it happen? Seems weird. And is there a way to fix it without having to cast? I didn't expect that modularizing my app would lead to a decline in code quality 😕manueldidonna
06/25/2020, 2:36 PMdata class Item(val id: Int)
fun randomItem(block: (Int) -> Item) {}
// this
List(100) { randomItem(::Item) }
// vs
val constructor = ::Item
List(100) { randomItem(constructor) }
Joel
06/25/2020, 10:47 PMassertEquals(
BigDecimal("0.08333333333333333"),
(1.toBigDecimal() / 12.toBigDecimal())
)
expected: <0.08333333333333333> but was: <0>
The bottom evaluates to 0
which is clearly incorrect. What is the rule here and how can I avoid this pitfall?Slackbot
06/26/2020, 8:36 AMsikri
06/26/2020, 8:44 AMcoerceAtLeast
has more priority then -
? -2.coerceAtLeast(0) == -2
Joakim Tengstrand
06/26/2020, 12:14 PMtorres
06/26/2020, 1:13 PMfun main(args: Array<String>) {
var tree = Node("A", null, null)
val q: Queue<Node> = LinkedList()
q.add(tree)
tree = q.remove() // line 5, remove element in q and assign to tree so tree so should size 0
println(tree.data) // line 6, why does this still print "A" though?
}
// given
class Node {
var data: String
var left: Node? = null
var right: Node? = null
constructor(data: String) {
this.data = data
}
constructor(data: String, left: Node?, right: Node?) {
this.data = data
this.left = left
this.right = right
}
}
rrva
06/26/2020, 2:04 PMevanchooly
06/26/2020, 4:11 PMZach Klippenstein (he/him) [MOD]
06/26/2020, 7:23 PMAntonios Barotsis
06/26/2020, 8:32 PMnkiesel
06/27/2020, 12:14 AMError:Kotlin: [Internal Error] java.rmi.ServerError: Error occurred in server thread; nested exception is:
java.lang.OutOfMemoryError: Java heap space
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:386)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:303)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:279)
...
Caused by: java.lang.OutOfMemoryError: Java heap space
at org.jetbrains.kotlin.incremental.storage.ProtoMapValueExternalizer.read(externalizers.kt:63)
at org.jetbrains.kotlin.incremental.storage.ProtoMapValueExternalizer.read(externalizers.kt:48)
at com.intellij.util.io.PersistentHashMap.doGet(PersistentHashMap.java:616)
at com.intellij.util.io.PersistentHashMap.get(PersistentHashMap.java:560)
at org.jetbrains.kotlin.incremental.storage.CachingLazyStorage.get(CachingLazyStorage.kt:64)
at org.jetbrains.kotlin.incremental.IncrementalJvmCache$ProtoMap.get(IncrementalJvmCache.kt:307)
at org.jetbrains.kotlin.incremental.IncrementalJvmCache.getModuleMappingData(IncrementalJvmCache.kt:267)
Paul Woitaschek
06/27/2020, 7:58 AMAntonios Barotsis
06/27/2020, 10:40 AMAntonios Barotsis
06/27/2020, 10:40 AMIaroslav Postovalov
06/27/2020, 12:42 PMAntonios Barotsis
06/27/2020, 12:42 PMandylamax
06/27/2020, 12:53 PMAntonios Barotsis
06/27/2020, 1:06 PMNikky
06/27/2020, 11:00 PM