Marc Knaup
05/08/2019, 2:30 PMpajatopmr
05/08/2019, 4:40 PMiex
05/08/2019, 6:09 PMval nonOptional = optional ?: Log.e("foo", "optional is not set").also { return }
Dico
05/08/2019, 8:49 PMPaul Woitaschek
05/09/2019, 7:32 AMval imageSource = suspendCoroutine<ImageSource> { cont ->
MaterialDialog(context).show {
listItems(
items = ImageSource.values().map { getString(it.nameRes) },
selection = { _, i, _ ->
val imageSource = ImageSource.values()[i]
cont.resume(imageSource)
}
)
}
}
val uri = when (imageSource) {
ImageSource.GALLERY -> {
module<SelectPictureFromGalleryModule>().take()
}
ImageSource.TAKE_PICTURE -> null
}
into this:
val uri = when (suspendCoroutine<ImageSource> { cont ->
MaterialDialog(context).show {
listItems(
items = ImageSource.values().map { getString(it.nameRes) },
selection = { _, i, _ ->
val imageSource = ImageSource.values()[i]
cont.resume(imageSource)
}
)
}
}) {
ImageSource.GALLERY -> {
module<SelectPictureFromGalleryModule>().take()
}
ImageSource.TAKE_PICTURE -> null
}
pablisco
05/09/2019, 9:58 AMJUNIT
one but could not find any documentation (wondering what the CANVAS
one is about too 😄 )reik.schatz
05/09/2019, 10:04 AMnickk
05/09/2019, 2:50 PMObject
?
Say, I want a shorter name for Android’s `getString()`:
@NonNull
public final String getString(@StringRes int resId, Object... formatArgs) {
return getResources().getString(resId, formatArgs);
}
How do I write a Kotlin function that just forwards its arguments to this getString
?
According to the docs, I should use kotlin.Any!
Android Studio does not even let me add the !.
Using just vararg Any
results in IllegalFormatExceptions
Ovsyannikov Alexey
05/10/2019, 12:28 AMBroadcastChannel#asFlow
extension is using consumeEach
. After this I've found (https://github.com/Kotlin/kotlinx.coroutines/blob/085a4cb7dec4121f51cda832dbe1e223681d3379/kotlinx-coroutines-core/common/src/channels/Channels.common.kt) source file and remember that most part (maybe, all) of consume* methods are obsolete for now. How it will be replaced in flows and when these obsolete extensions will be removed?elect
05/10/2019, 10:27 AMbodiam
05/11/2019, 4:25 AMOvsyannikov Alexey
05/11/2019, 10:28 AMaerb
05/11/2019, 12:32 PMkrtko
05/11/2019, 8:15 PMelect
05/12/2019, 8:34 AMYossi Saiada
05/12/2019, 9:28 AMenum class EnumA {
A, B;
val group = EnumB.values().find { this == it.enumA }
}
enum class EnumB(val enumA: EnumA) {
A1(EnumA.A),
B1(EnumA.B),
}
EnumB.values().map { it.enumA } // => [null, null]
EnumA.A.group // == null
EnumB.values().find { EnumA.A == it.enumA }
Why does EnumB.enumA, for every EnumB value, equals null
?
(I know it's happening because of the circular dependency (caused by the group property), but I'm not sure it should be like that)
Edit:
I'm a bit confused. I had thought the reason is the circular dependency, but this code:
enum class EnumA(val enumB: EnumB) { A(EnumB.B) }
enum class EnumB(val enumA: EnumA) { B(EnumA.A) }
EnumB.values().map { it.enumA }
actually works as expected and return [A]
. 🤨Heart D
05/12/2019, 5:59 PMViktor Qvarfordt
05/12/2019, 8:55 PMHeart D
05/13/2019, 8:11 AMBernhard
05/13/2019, 10:15 AMamadeu01
05/13/2019, 12:39 PMelect
05/13/2019, 1:54 PMinline fun method(lambda: () -> Unit) // Java needs at the end `return Unit.INSTANCE;`
void method(Runnable lambda) // Kotlin needs to wrap it into `Runnable { }` and you dont have inline
pdegand
05/13/2019, 4:05 PMsealed class Bird
class Chicken: Bird()
class Turkey: Bird()
class Egg<T: Bird>
I want to implement a function fun <T: Bird> T.layEgg(): Egg<T>
.
The only way I found to implement it with the compiler being ok with is like that :
fun <T: Bird> T.layEgg(): Egg<T> {
return when(this as Bird) {
is Chicken -> Egg<Chicken>()
is Turkey -> Egg<Turkey>()
} as Egg<T>
}
fun main() {
val egg: Egg<Chicken> = Chicken().layEgg()
}
But IDEA tells me that the first as Bird
in the when is useless, but if I remove it, the compiler complains that the when is not exhaustive.
And the final as Egg<T>
is marked as unsafe but I need it because returning an Egg<Chicken> is not and Egg<T>.
Is there a way to have this implemented a better wat or is this simply impossible with generics ?
ThanksPaul Woitaschek
05/13/2019, 4:19 PMinline class Calories(val value : Double)
But now I lose all functionallity of double. If I for example want to sum, substract or divide calories, I need to re-implement these basic math functions ontop of the Calories
class as operator fun plus
etc.Chi
05/13/2019, 4:40 PM!!
in my while
loop, while I already check node.right will never be nullserebit
05/13/2019, 5:13 PMGuru
05/14/2019, 5:58 AMconst com = {
to:"guru",
address: {
add1: "DC",
add2: "LA"
},
phoneno: 767646
}
const fu = ({address:{add1}, phoneno})=>
{
console.log(JSON.stringify(add1));
}
fu(com)
joelpedraza
05/14/2019, 3:22 PMvalue
property is internal how can accessors such as fold
be marked as inline
?Nezteb
05/14/2019, 4:10 PMAndy Victors
05/14/2019, 5:16 PMobjects
being frozen - technical limitation or a language concept?
What us then the alternative of keeping the global modifiable list of, say, users in the app?