I have a scala project and I try to implement a service requiring access to an Amazon S3 bucket.

I want to get a list of all the objects of a bucket, yet the result set of `s3Client.listObjects` is paginated to a 1000 items.

One has to fetch multiple objectListings in order to get all results.

I have found an [example Java implementation](https://www.programcreek.com/java-api-examples/?class=com.amazonaws.services.s3.AmazonS3&method=listNextBatchOfObjects) yet it relies on mutability (overwriting the objectListing in the while loop):

```
AmazonS3 s3Client = AmazonS3Provider.getS3Client();
ListObjectsRequest req = new ListObjectsRequest().withBucketName(realBucket).withPrefix(!preprefix.equals("") ? preprefix + "/" + prefix : prefix);
ObjectListing objectListing = s3Client.listObjects(req);
List<S3ObjectSummary> summaries = objectListing.getObjectSummaries();

while (objectListing.isTruncated()) {
    objectListing = s3Client.listNextBatchOfObjects(objectListing);
    summaries.addAll(objectListing.getObjectSummaries());
}

```

While I can translate that into scala fine, I want to use a more idiomatic scala way.

How can I get all pages of a bucket using scala?