All,
I am having an issue here with Groovy. Specifically I would like to use the inject method on a current list that I have. I need this list to be Immutable and built per element. Here is what my list looks like:
def initialList = [ "A", "B", "C" ]
I want to be able to to use an inject statement to add/build to this list on the fly and assign it to a variable. The desired code should look something like the following:
def result = initialList.inject(){ initialList + valueOfNextLetter() }
Obviously the semantics of this inject are escaping me. I have a function that will return the next value, but I cannot seem to get the list added element by element. What is the ideal result is code that will take the current state of initialList, return the next value, and then inject the processed result at the end of initialList. I cannot seem to understand Groovy inject. Please help. Any comments are helpful.