I’m reading the Gatling source, in particular Session.scala. In part because I’m trying to extract enough of it to test my development of a session management DSL, and in part to just understand Scala a little better…
The code looks like this:
def update(updates: Iterable[Session => Session]): Session = updates.foldLeft(this) { (session, update) => update(session) }
What I’m seeing, in English, is this:
Takes in an object which is an Iterable (e.g. list, seq, etc.) of functions that take in a Session and return a Session. The implementation uses foldLeft to iterate over the list, calling the function in that position in the list using the current session, which returns a new session which is then passed in to the next function, and so on down the list. End result is a new session object. It took a little time to parse it and understand it, but I got the gist of it.
But why does this method exist? What is the use case for it? Why isn’t there an update that takes in a single function, instead of a list (iterable) of functions?