alex.hart
07/25/2019, 5:42 PMSteve
07/25/2019, 5:44 PMgeepawhill
07/25/2019, 5:49 PMclass X : List<Y> by myList { private val myList = mutableListOf<Y>()
Failing that as a simple declaration, is the clever way to do it maybe make the primary constructor private and offer secondary constructors to call it?Gunslingor
07/25/2019, 5:56 PMfangzhzh
07/25/2019, 9:02 PMval result = value * 100.0 / 255
Given that 100.0/255=0.392, is val result = value * 0.392
better than the equation one in the performance of view.aurimas
07/25/2019, 10:37 PMvpriscan
07/26/2019, 8:10 AMKindRoacher
07/26/2019, 8:37 AMvpriscan
07/26/2019, 8:42 AMJan
07/26/2019, 12:44 PMtenprint
07/26/2019, 2:03 PMMyJavaClass {
MyKotlinClass myKotlinClass;
void myMethod() { ... }
... myKotlinClass.foo(this::myMethod);
}
What should be the parameter in fun foo( ? )
?twisterrob
07/26/2019, 6:22 PMfun <E> Collection<E>.myContains(item: E) : Boolean
usage: val isItInside: Boolean = listOf(1, 2).myContains("1")
expectation: usage fails to compile, because it's a List<Int>
vs. a String
https://stackoverflow.com/q/57224118/253468pajatopmr
07/27/2019, 7:39 AMcorneil
07/27/2019, 12:25 PMIve Vasiljevic
07/27/2019, 1:25 PMGunslingor
07/27/2019, 9:17 PMPablichjenkov
07/28/2019, 5:42 AMclass SomeClass {
var aVar: OtherClass? = null
fun aFunction() {
aVar?.let {
//doSomething with aVar since 'it' is not null
} ?: run {
//doSomething else when aVar is null
}
}
}
I know that I can do this:
fun aFunction() {
val aVarLocalCopy = aVar
if (aVarLocalCopy != null) {
//doSomething with aVarLocalCopy
} else {
//doSomething else when aVarLocalCopy is null
}
}
But I don’t like the fact of creating one line of code to extract the thread safe local reference copy of aVarProperty. Any pattern or extension function to write above code shorter.vpriscan
07/28/2019, 11:38 AMdave08
07/28/2019, 2:07 PMmappingFunction
...:
@Nullable V get(@NonNull K key, @NonNull Function<? super K, ? extends V> mappingFunction);
I really don't know what could be wrong:
suspend inline fun <reified K : Any, reified V : Any> Cache<K, V>.get(key: K, crossinline mappingFunction: suspend (K) -> V): V? =
get(key) { runBlocking { mappingFunction(it) } }
it's probably related to the generics... 🤕CLOVIS
07/28/2019, 9:58 PM//1
Something<Pair<A, B>>
//2
data class Other<A, B>(...)
Something<Other<A, B>>
//3
typealias Other<A, B> = Pair<A, B>
Something<Other<A, B>>
I'm expecting that the answer is "it depends", what are some good examples to choose which one to use?Kroppeb
07/28/2019, 10:18 PMNothing
. This doesn't happen if assigned to a new var/valDennis Schröder
07/29/2019, 9:00 AMbitkid
07/29/2019, 9:42 AMwidar
07/29/2019, 9:46 AMMichał Kalinowski
07/29/2019, 11:27 AMJoffrey
07/29/2019, 5:48 PMFlow
of lines from a File
(on JVM)?
I thought about several options, like:
- FileReader(file).buffered().lineSequence().asFlow()
(requires to close reader externally)
- flow { FileReader(file).useLines { lines -> lines.forEach { emit(it) } } }
(broken reader closure it early termination)
But I believe that would be using the blocking file API behind the scenes. Is this OK, though?
Should I implement my flow on top of AsynchronousFileChannel
instead?Imran/Malic
07/29/2019, 6:51 PMStefan Beyer
07/30/2019, 1:01 PMfun foo(a: Boolean, b: Boolean) = when { // "when expression must be exhaustive" error
a == b -> "same"
a -> "first"
b -> "second"
// this actually IS exhaustive:
// a | b | result
// ---+---+--------
// 0 | 0 | same
// 1 | 0 | first
// 0 | 1 | second
// 1 | 1 | same
}
Do you guys think this is an issue that should be reported? 🙂
edit: I am not sure because surely this is just one example of a whole bunch of those cases and I personally would not want to implement thousands of corner cases into a language feature. (After all, this is a language, not platformer physics 😄)stellarspot
07/30/2019, 1:17 PMinline
is used as
The inline modifier affects both the function itself and the lambdas passed to it: all of those will be inlined into the call site.
In case you want only some of the lambdas passed to an inline function to be inline, you can mark some of your function parameters with the noinline modifier:
What If I do not need to make the whole function inline but want that its passed lambdas are made inline?
For example my function have private fields and to make it inline it is necessary to annotate the whole function with @Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
.
If a function with lambda arguments is not marked as inline
will the compiler smart enough to inline the lambda in the function body if the only lambda usage is its invocation?
https://kotlinlang.org/docs/reference/inline-functions.htmligor.wojda
07/30/2019, 1:31 PMis
prefix for Boolean returning methods is quite straight forward. I wonder what are you thoughts on adding is
prefix to Boolean properties?
// method
view.isVisible()
// property
view.visible
or
view.isVisible
igor.wojda
07/30/2019, 1:31 PMis
prefix for Boolean returning methods is quite straight forward. I wonder what are you thoughts on adding is
prefix to Boolean properties?
// method
view.isVisible()
// property
view.visible
or
view.isVisible
karelpeeters
07/30/2019, 1:39 PMvisible
but it's an internal struggle every time 😒imple_smile:dalexander
07/30/2019, 1:42 PMStefan Beyer
07/30/2019, 1:45 PMview.isVisible
, but it depends on whether you need the accessors to be used (by java code or some lib like jackson)
// kotlin
class Foo(val cool:Boolean,val isHot:Boolean)
// java
public class Java {
public static void main(String[] args) {
Foo foo = new Foo(true, true);
foo.getCool(); // not very cool :(
foo.isHot();
}
}
you could add @getter:JvmName("isCool")
to the property, but this is uglier than in the first place ^^karelpeeters
07/30/2019, 1:47 PMdalexander
07/30/2019, 1:49 PMisFoo
pretty heavily.arekolek
07/30/2019, 2:14 PMisVisible: Boolean
rather than visible: Boolean
Because of java interop, but also like I would write hasChildren: Boolean
and not children: Boolean
Also, there’s #codingconventions 😉igor.wojda
07/30/2019, 2:22 PMarekolek
07/30/2019, 3:13 PMview.takeIf { it.isVisible }
reads better than view.takeIf { it.visible }