Let's say, that we keep track of students entering the auditorium using their IDs(Key) and their check-in time(Value) in a Map. We delete the entries once they move out of the auditorium. I want to know at a given point in time who all are there in the auditorium and when did they check-in. All Imperative languages do the job.
But, The functional programming examples/gurus simply explain like the below: take input map, add the entry and return the output map. similarly for delete. Thus we don't modify the input. All of this advice works for the frozen data sets given the knowledge of what will happen in advance while writing the code.
But in this scenario, how would we know how many variables should I create in advance to store the newer versions of the immutable maps after insert/delete? Let's discuss this from an API perspective where we expose an endpoint to a device that tracks the check-in/check-out of the students.
OR Is there any other smart way to know the current state of the auditorium in Functional programming without doing any of the above?
NOTE: Please do not simply advise that FP is not suitable for doing these kinds of tasks. Let's say we have already taken up a project in FP and encounter the above scenario. What will you do :)?