Reputation: 13501
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?
Upvotes: 0
Views: 108
Reputation: 20816
You can append b
to the end of its objects, e.g.,
val objects = buckets.flatMap { b => Observable.from(
S3.listObjects(new ListObjectsRequest().withBucketName(b.getName))
.getObjectSummaries
.asScala) :+ b
}
Upvotes: 1