I am sure that there is a good reason for this, but I do not see it.
Fold on (say) List returns
the result of applying the bend operator op between all elements and z
It has an obvious connection with foldLeft and foldRight , which do the same, but with a specific order (and therefore no associative operators are needed)
Fold on Option returns
Returns the result of applying f to this scala.Option value if scala.Option is scala.Option empty. Otherwise, the ifEmpty expression is ifEmpty .
ifEmpty (at position) z for the list. f (in position) op
For None (which, using my mental model Option as a “container”, which may or may not contain a value, is an “empty” container), everything is fine, Option.fold returns zero ( ifEmpty value).
For Some(x) , however, f should not take two parameters z and x so that it matches the Fold sequences (including a similar relationship with foldLeft and foldRight ).
There is definitely a utility argument - having f , just take x as a parameter in practice, probably more convenient. In most cases, if he also took z , which would be ignored. But consistency is also important ...
So can someone explain to me why Fold on Option is still the “right” Fold ?