Appending to a list when saving

Hi everyone,
I am working on a script with an extraction of multiple items from a JSON response similar to this example:

jsonPath("$[*].id").findAll.saveAs(“ids”)

I was looking for an “easy” way to not only save the just extracted ids, but also appending them to an already existing list in the session (since the request with this extraction is executed in a loop).
Unfortunately I don’t find anything like:
.saveAs(“ids”, append=true)

Is that so that the way to achieve that is to implement an Expression[Session] (or an ActionBuilder?) doing it, provide it with the source and target session attribute identifiers and then execute in an .exec() after the relevant request?
Like:
exec(requestDefinitionWithAnExtractionThatSavesIds)
.exec(myAppendingExpression(sourceAttr=“ids”, destAttr=“allIdsList”))

Regards,
Tomasz

Is that so that the way to achieve that is to implement an Expression[Session] (or an ActionBuilder?) doing it, provide it with the source and target session attribute identifiers and then execute in an .exec() after the relevant request?
Like:
exec(requestDefinitionWithAnExtractionThatSavesIds)
.exec(myAppendingExpression(sourceAttr=“ids”, destAttr=“allIdsList”))

Exactly.

In Java:

exec(session -> {
  List<String> ids = session.getList("ids");
  session.getList("allIds").addAll(ids);
  return session.remove("ids");
})

Thanks a lot!

Maybe a follow up question,
should I worry/prefer if the collection that I am storing in the session is immutable/mutable?
So in Scala for example: immutable.Set vs mutable.Set , is one of these preferred?

I see Gatling itself using immutable.Vector would that be a hint :-)?

Regards,
Tomasz