I'm a beginner in Scala. Is there a concise way to write the following nested case statement?
def delete(
client : TwitterRestClient,
userId : Long,
keyword : String) : Unit = {
client.userTimelineForUserId(userId).onComplete{
case Success(value) => {
value.data.filter(_.text.contains(keyword)).foreach(x => {
client.deleteTweet(x.id).onComplete{
case Success(value) => println(s"Success: $value")
case Failure(exception) => println(s"Fail: $exception")
}
})
}
case Failure(exception) => println(s"Fail:$exception")
}
Slightly different way using
flatMap, sequencingFuturesand usingcollectinstead offilterandmap:I have only compiled the code, dint run it.