halirutan
07/29/2018, 12:39 AM.
in Java/Kotlin and the last part is the name and the first part is the namespace (it's called context). Namespaces can be nested like in Java too, so there might be symbol thats in ``My`name`space`symbol``.
A simple datastructure for this is to have a hashset with entries fullSymbolNames -> symbolInformation
but I have some operations that need to be blazingly fast because they are called very often
1. Does symbol Plot
exist in the namespace ``System` ``? This can easily be done by prepending the namespace to the symbol-name and simply check if the keys contain such an entry
2. In which namespaces does the symbol FooBar
exists? Not really fast as I have to filter the whole list of values or process all keys.
3. What symbols are in the namespace PacletManager
? Again, I need to filter all values for this.
My current implementation in Java makes this possible by handling several different hashsets/lists but I wonder if anyone can think of a better data-structure to make the 3 operations fast. Note that once I loaded all the information about symbols, the data is read-only and I do not mutate any of it.martmists
07/29/2018, 3:52 AMfun zipFiles(path: String = "/path/to/dir"): File
elect
07/30/2018, 9:33 AMmarstran
07/30/2018, 12:41 PMcategories != null
. The compiler cannot infer that it's not null from the .orEmpty().isEmpty()
call.orangy
07/30/2018, 2:37 PMkrtko
07/30/2018, 6:23 PMpassiondroid
07/30/2018, 6:50 PMbrabo-hi
07/31/2018, 1:27 AMAregev2
07/31/2018, 8:48 AMWildRhum
07/31/2018, 11:48 AMarekolek
07/31/2018, 2:43 PM@file:JvmName("TestCompanion")
const val FOO = "FOO"
class TestCompanion {
}
produces byte code that decompiles to:
import org.jetbrains.annotations.NotNull;
public final class TestCompanion {
@NotNull
public static final String FOO = "FOO";
}
Hexa
07/31/2018, 3:16 PMMap<String, List<Items>
into a Map<String, List<Product>>
, example: val someMap: Map<String, List<Items>> = x
val newMap: Map<String, List<Product>> = someMap.map { it. } ??? what to do here?
Kiongku
07/31/2018, 3:38 PMval newMap: Map<String, List<Product>> = someMap.mapValues { it.value.map { Product(it.brand, it.type) } }
frellan
07/31/2018, 8:12 PMMap<Int, List<Stuff>> -> List<NewStuff>
where new stuff is yielded from each list of stufffrellan
07/31/2018, 8:16 PM.flatMap
but instead of recieving each entry I want to recieve all values belong to a keypavel
07/31/2018, 9:01 PMdata class Author(val books: List<Book>)
data class Book(val name: String, val author: Author)
fun Author.withBook(book: Book): Author = this.copy(books = this.books + book)
adams2
07/31/2018, 10:20 PMeygraber
08/01/2018, 6:22 AMthis::class.java
and javaClass
in regards to generics?
If I have this class defined:
class Test<T>(
val me: Class<T>
)
And I instantiate it like this, it's fine:
fun <T> T.test() {
Test(javaClass)
}
However, if I instantiate it like this, it won't compile:
fun <T> T.test() {
Test(this::class.java)
}
And the error is:
Type inference failed. Expected type mismatch:
Required: Test<T>
Found: Test<out T>
christophsturm
08/01/2018, 8:34 AMSlackbot
08/01/2018, 9:51 AMRuckus
08/01/2018, 7:13 PMfun <T> MutableList<T>.upsert(source: List<T>, predicate: (existing: T, new: T) -> Boolean) {
for (item in source) {
val index = indexOfFirst { predicate(it, item) }
if (index >= 0) set(index, item) else add(item)
}
}
(Note that it's adding to the list while still using it. You may want to save new items to a separate list and add them all at the end after processing.)anosov
08/01/2018, 7:35 PMsupaham
08/02/2018, 4:05 PMelect
08/02/2018, 5:54 PMamatkivskiy
08/03/2018, 7:51 AMcheckNotNull()
compiler still thinks that the value
can be null?
class TargetClass(private val value: String? = null) {
fun functionThatUsesValue() {
checkNotNull(value)
// Still need to add ?. to the value call
println("split: ${value?.split(" ")}")
}
}
fun main(args: Array<String>) {
val target = TargetClass()
target.functionThatUsesValue()
}
rrader
08/03/2018, 8:31 AMclass RedisCache { }
typealias Cache = RedisCache
if we need to chenge it
class MongoCache { }
typealias Cache = MongoCache
Jan Vomlel
08/03/2018, 10:21 AMpakoito
08/03/2018, 10:48 AMfun <B> B?.bla() = 1
and fun <B: Any?> B.bla() = 1
diesieben07
08/03/2018, 11:50 AMval input = listOf(4, 1, 1, 3, 2, 5, 2)
val output = input.chunkedBy { it % 2 == 0 } // should be: [[4, 1, 1, 3], [2, 5], [2]]
Is there such a thing in the standard library?orafaaraujo
08/03/2018, 7:56 PMtoString()
when using data class
?
Something like an annotation...orafaaraujo
08/03/2018, 7:56 PMtoString()
when using data class
?
Something like an annotation...Andreas Sinz
08/03/2018, 7:57 PMorafaaraujo
08/03/2018, 7:58 PMadam-mcneilly
08/03/2018, 8:04 PMorafaaraujo
08/03/2018, 8:10 PM