This is a question about reduce and fold more related to functional programming than specifically to scala. I want to implement my own application version of reduce which has an extra optimization feature. But I don’t know what to call the feature.
Consider the multiplication function, if it is being used as an argument to fold, then if the accumulated result ever becomes zero, then I want to terminate the iteration, and simply return 0, without visiting the remaining elements. Similar for the AND and OR functions. When folding with AND, I want to terminate and return false if the result ever becomes false; and when folding with OR, I want to terminate as soon as the result becomes true.
What should this terminating value be called? (argument-wise) and what is the correct way to document its behavior?