小编Wil*_*ill的帖子

在Kotlin从lambda隐含回归

看起来lambda的最后一行总是返回该值,即使你省略了该return语句.它是否正确?是否记录在任何地方?

fun main(args: Array<String>) {
    val nums = arrayOf(1, 2, 3)
    val numsPlusOne = nums.map { it -> 
        val r = it + 1
        r
    }
    // numsPlusOne = [2, 3, 4]
}
Run Code Online (Sandbox Code Playgroud)

kotlin

23
推荐指数
1
解决办法
7697
查看次数

如何调试Kotlin序列/集合

采用以下单行,可以表示为对集合或序列的一系列操作:

val nums = (10 downTo 1)
        // .asSequence() if we want this to be a sequence
        .filter { it % 2 == 0 }
        .map { it * it }
        .sorted()
        // .asList() if declaring it a sequence

println(nums)   // [4, 16, 36, 64, 100]
Run Code Online (Sandbox Code Playgroud)

假设我想在每一步看到元素,它们将是(来自演绎):

[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
[10, 8, 6, 4, 2]
[100, 64, 36, 16, 4]
[4, 16, 36, 64, 100]
Run Code Online (Sandbox Code Playgroud)

不幸的是,没有好的方法可以使用调试器对其进行调试,也可以记录这些值以供以后检查.使用良好的函数式编程结构,整个方法可以重写为这样的单个语句,但似乎没有好的方法来检查中间状态,甚至计数(10, 5, 5, 5这里).

调试这些的最佳方法是什么?

intellij-idea kotlin

6
推荐指数
3
解决办法
1088
查看次数

Firebase 远程配置推送需要多长时间?

推送远程配置需要多长时间?我有以下代码,在网络上推送新更新后,它会继续打印 false 和旧值至少几分钟。

remoteConfig.fetchWithCompletionHandler { (status, error) -> Void in
    if (status == FIRRemoteConfigFetchStatus.Success) {
        print("Config fetched.")
        print(self.remoteConfig.activateFetched())
        print(self.remoteConfig.configValueForKey("my_key").stringValue)
    } else {
        print("Config not fetched.")
    }
}
Run Code Online (Sandbox Code Playgroud)

ios firebase swift firebase-remote-config

4
推荐指数
1
解决办法
4471
查看次数