【发布时间】:2019-02-17 22:06:45
【问题描述】:
我正在使用fuel http 发出一个简单的 GET 请求。 这是我的代码:
fun fetchTweets(): List<Tweet> {
endpoint.httpGet(listOf("user" to "me", "limit" to 20))
.responseObject(Tweet.Deserializer()) { _, _, result ->
result.get().forEach { Log.i("TWEET", it.text) }
val tweets = result.get().toList() //I want to return this
}
}
如果我在val tweets 下方执行return tweets,则会收到错误消息:
return is not allowed here.
这对我来说很有意义。但是问题仍然存在,我如何编写一个函数来返回在 lambda 中创建的变量?在这种情况下,我想返回tweets
【问题讨论】:
标签: android kotlin concurrency functional-programming