Build a value using each element in the list.
Starting with a given state value, this folds through each element in the
list from first to last, running a given step function on that element
which updates the state. It returns the final state at the end.
[2, 4, 8].fold(0, U64.plus)
This returns 14 because:
* state starts at 0
* Each step runs state.plus(elem), and the return value becomes the new state.
Here is a table of how state changes as List.fold folds over the elements
[2, 4, 8] using U64.plus as its step function to determine the next state.
state | elem | U64.plus(state, elem)
:---: | :---: | :----------------:
0 | |
0 | 2 | 2
2 | 4 | 6
6 | 8 | 14
The following returns -6:
[1, 2, 3].fold(0, I64.minus)
Note that in other languages, fold is sometimes called reduce,
fold_left, or foldl.