I'd like to observe a tree of objects, in reverse dependency order, but do not know what combinators to use. The specific case is iterating through AWS Resources in order for deletion, for example deleting S3 Objects before deleting their S3 Buckets, like this:
val S3 = new AmazonS3Client
val buckets = Observable.from {
S3.listBuckets.asScala
}
val objects = buckets.flatMap { b => Observable.from(
S3.listObjects(new ListObjectsRequest().withBucketName(b.getName))
.getObjectSummaries
.asScala)
}
val combined:Observable[_] = ???
for (thing <- combined) thing match {
case b:Bucket => println("delete bucket")
case o:S3ObjectSummary => println("delete object")
}
So, the final combined
observable should emit all the objects before emitting the bucket. What combinator should i use for that?
答案 0 :(得分:1)
您可以将b
附加到其对象的末尾,例如
val objects = buckets.flatMap { b => Observable.from(
S3.listObjects(new ListObjectsRequest().withBucketName(b.getName))
.getObjectSummaries
.asScala) :+ b
}