I'm trying to learn Scala and having a good bit of fun, but I'm running into this classic problem. It reminds me a lot of nested callback hell in the early days of NodeJS.
Here's my program in psuedocode:
- A task to fetch a list of S3 Buckets.
- After task one completes I want to batch the processing of buckets in groups of ten.
- For each batch:
- Get every bucket's region.
- Filter out buckets that are not in the region.
- List all the objects in each bucket.
- println everything
At one point I wind up with the type: Task[Iterator[Task[List[Bucket]]]]
Essentially:
The outer task being the initial step to list all the S3 buckets, and then the inside Iterator/Task/List is trying to batch Tasks that return lists.
I would hope there's some way to remove/flatten the outer Task to get to Iterator[Task[List[Bucket]]]
.
When I try to break down my processing into steps the deep nesting causes me to do many nested maps. Is this the right thing to do or is there a better way to handle this nesting?