camkadev
11/02/2018, 5:24 AMgildor
11/02/2018, 9:22 AMckchen
11/02/2018, 9:37 AMFredrik Larsen
11/02/2018, 9:38 AMBarend
11/02/2018, 9:40 AMGlobalScope.launch(Dispatchers.Main)
throw a Fatal Exception: android.os.NetworkOnMainThreadException
and GlobalScope.async
doesn't?Nikky
11/02/2018, 9:58 AMEach Enum constant is an object
Jakub
11/02/2018, 10:41 AMsamir
11/02/2018, 11:07 AMval imap = mapOf("a" to "a")
// val mmap = imap as MutableMap
imap["b"] = "b" //compiler error
val imap = mapOf("a" to "a")
val mmap = imap as MutableMap
imap["b"] = "b" //runtime error java.lang.UnsupportedOperationException
orestisfou
11/02/2018, 12:01 PMyen
11/02/2018, 12:27 PMbod
11/02/2018, 1:53 PMspand
11/02/2018, 2:54 PMapi
method for the dependencies block. Is there a kotlin verion of this ? (do I need one ?)Paul Woitaschek
11/02/2018, 3:44 PMfun d(x : X, y : Y)
it's painful to change all that code just for passing them through from fun a(x : X, y : Y)
-> fun b(x : X, y : Y)
-> fun c(x : X, y : Y)
-> fun d(x : X, y : Y)
.
Are there any common approaches / patterns to solve this?Paul Woitaschek
11/02/2018, 3:56 PMpurchaseCardContents
calls purchaseCardContents
which calls toPurchaseCardContent
several times.
Now I need a class FormatSavings
in the last function toPurchaseCardContent
.
How do I get it there? When using a class for the whole logic, I just inject it through the constructor.
The issue here is that toPurchaseCardContent
doesn't know anything about purchaseCardContents
so I would need to pass-through that class and everything else it needs.
Maybe the better question is: How do I get / pass dependencies I don't want the caller to bother about in functional programming?marcelo
11/02/2018, 4:29 PMcoroutines
. Don't know why this code
experienceTimer.tagVal("/sdsd/login").time {
Thread.sleep(2)
}
unless I have
suspend {
experienceTimer.tagVal("/sdsd/login").time {
Thread.sleep(2)
}
}
Don't think I am doing this right. I feel like the show Pimp My Ride,
Yo dawg, I heard you likeso I am adding asuspend
and a block ofsuspend
within the method that I want tosuspend
.suspend
nickheitz
11/03/2018, 9:28 AMhudsonb
11/03/2018, 12:19 PM->
in the else
of the `when`:
internal fun hue(a: Double, b: Double): (Double) -> Double {
val d = b - a
return when {
d.isTruthy() -> linear(a, if (d > 180 || d < -180) d - 360.0 * Math.round(d / 360.0) else d)
else -> { _ -> if(a.isNaN()) b else a } // Redundant lambda arrow
}
}
Removing it changes the type from (Double) -> Double
to Double
. Is there a better approach?Hunter Breathat
11/03/2018, 4:15 PMkingsley
11/03/2018, 4:35 PMsubprojects {
afterEvaluate {
the<KotlinProjectExtension>().sourceSets.all {
languageSettings(closureOf<LanguageSettingsBuilder> {
progressiveMode = true
enableLanguageFeature("NewInference")
enableLanguageFeature("InlineClasses")
...
useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
})
}
}
}
edwinRNDR
11/03/2018, 6:05 PMTolriq
11/03/2018, 7:03 PMpublic final class Cast {
public static final Cast.CastApi CastApi;
private Cast() {
}
public interface CastApi {
}
}
Accessing the static final field from Kotlin seems impossible AS always think I'm referring to the interface and not the field, is there any trick for that?Benoit Duffez
11/03/2018, 9:15 PMfun foo(bar: Long) { ... }
//elsewhere:
fun whatever(baz: Long?) = return when {
baz ?: 0 > 0 -> foo(baz) // here
else -> null
}
why is there no smart cast for baz being non null here?APXEOLOG
11/03/2018, 10:04 PMreturn behaviors
.map { it to it.getFullUpdate() }
.filter { it.second != null }
.map { it.second.doSmth(it.first) } // Still nullable
getFullUpdate()
can return null, any way i can smart cast it.second
to non-null?karelpeeters
11/03/2018, 10:53 PM.mapNotNull { it.second }.map{ it.doSmth(it.first) }
Hexa
11/04/2018, 11:08 AMundefine
when I'm expecting it should be either true
or false
? obj shouldBe instanceOf(SomeClass::class)
Mahdi Javaheri
11/04/2018, 1:29 PMMahdi Javaheri
11/04/2018, 2:13 PMopen class AquariumPlant(val color: String)
class GreenLeafyPlant(size: Int): AquariumPlant("Green")
fun AquariumPlant.print() = println("AquariumPlant")
fun GreenLeafyPlant.print() = println("GreenLeafyPlant")
fun staticExample() {
val plant = GreenLeafyPlant(size = 50)
plant.print() // this print's GreenLeafyPlant
val aquariumPlant: AquariumPlant = plant
aquariumPlant.print() // this print's AquariumPlant !! but in polymorphism should be GreenLeafyPlant
}
is there a way to bypass this and benefit from PolymorphismNikky
11/04/2018, 2:16 PMPlant<PlantType>
Hexa
11/04/2018, 3:45 PMinternal
so that it can be unit tested? or is there a better way to do it without marking it as internal or public?mzgreen
11/05/2018, 7:50 AMvar foo: String = "foo" // set is not invoked during initialization
set(value) {
print("SET $value")
field = value
}
init {
foo = "foo" // have to do this in order to invoke set function
}
property with custom setter can’t be lateinit