Hello everyone, I’ve been thinking about this problem where I have an arbitrary payload, for simplicity lets say its a string, and I want to run multiple transformations on it, returning the transformed string in the end. Is there a way for me to store each of the transformation functions in a list, and then fold this list over the initial string? I’ve been playing around with an example today and it seems like it should be possible but I’m stuck on the actual fold. Is there a cleaner way of doing this? Would it make more sense to represent this type of computation using a monoid/semigroup? Any insight here is greatly appreciated.
val func1 = (s: String) => s + " func1"
val func2 = (s: String) => s + " func2"
val procList = List(func1, func2)
val s = "beginning string"
procList.fold(s) { ... } // Actual folding logic