dimsuz
09/08/2017, 9:15 AMMutableMap
which accepts key and the lambda : (V?) -> V
and replaces a value at that key with what lambda returns (or puts value if it's absent)? I haven't found it, so thinking maybe I've missed some idiom...menegatti
09/08/2017, 9:16 AMmapValues
work for Map
menegatti
09/08/2017, 9:17 AMdimsuz
09/08/2017, 9:18 AMbamdmux
09/08/2017, 9:29 AMdimsuz
09/08/2017, 9:30 AMDave Leeds
09/13/2017, 2:11 AMStandard.kt
has two run()
functions - one takes a receiver and one does not. I'm trying to find a good use case for the one that does not take a receiver.Dave Leeds
09/13/2017, 2:12 AMDave Leeds
09/13/2017, 2:13 AMfun welcome() = "Hello"
fun farewell() = "Good-bye"
fun getFunction(b: Boolean) = if (b) ::welcome else ::farewell
// Not very readable
println(getFunction(true)())
// A little more readable
println(getFunction(true).invoke())
// Also a little more readable - possible use case for `run()`
println(run(getFunction(true)))
Dave Leeds
09/13/2017, 2:14 AMkarelpeeters
09/13/2017, 4:26 AMkarelpeeters
09/13/2017, 4:26 AMfun foo(event: () -> Unit = run) { ... }
ilya.gorbunov
09/13/2017, 4:29 AMrun
without receiver can be invoked in a scope, where you don't have a receiver, for example in top level function.
The original use case of run
was to execute a block of code and return the result of its last expression:
val result = run {
val a = getA()
val b = getB()
a + b
}
Later it was generalized with an overload with receiver, so one could change the value of this
inside the lambda.elect
09/13/2017, 8:07 AMinit{ }
on class properties when it's just 2/3 loc..Dave Leeds
09/14/2017, 12:58 AMgroostav
09/15/2017, 1:46 AMoperator plus
extension functions, it seems locked to using the kotlin.collections
(non) immutable extension functions insteadgroostav
09/15/2017, 1:46 AMgroostav
09/15/2017, 1:47 AMImmutableMap
on my pathilya.gorbunov
09/15/2017, 1:51 AMkotlinx.collections.immutable.*
the operators for read-only collections are chosen, because they are imported by default.ilya.gorbunov
09/15/2017, 1:53 AMelect
09/22/2017, 2:01 PMuntil
on `Enum`select
09/22/2017, 2:04 PMrangeTo
inside the Enum
itself without issues, but outside I get errorilya.gorbunov
09/22/2017, 2:35 PMelect
09/22/2017, 2:52 PMFormat
as following
https://github.com/kotlin-graphics/gli/blob/working/src/test/kotlin/gli_/coreLoadGen1d.kt#L14elect
09/22/2017, 2:53 PM..
even if I comment out rangeTo
at the end of the same enum
https://github.com/kotlin-graphics/gli/blob/working/src/main/kotlin/gli_/format.kt#L264elect
09/22/2017, 2:54 PM..
I am using in the test doesnt work anymoreilya.gorbunov
09/22/2017, 2:56 PMComparable<T>.rangeTo
is used. And it creates just range, not a progression, so it can't be iterated.elect
09/22/2017, 2:57 PMelect
09/22/2017, 2:58 PMgaetan
09/26/2017, 12:05 PMRounds the given value [a] to an integer towards negative infinity.and the implementation (js) is:
public inline fun floor(a: Double): Double = nativeMath.floor(a).unsafeCast<Double>()
Why returning a Double and not an Int?