reduce is more general than the definition on Collection , and the Combine framework even comes with a reduce on the Publisher protocol that has a similar signature: https://developer.apple.com/documentation/combine/fail/reduce( : :) .
@stephencelis Thank you for the link and the additional examples for the reduce function (and for TCA of course, I love it!). Let me quote how Apple explains what Combines reduce function does in that link:
Applies a closure that collects each element of a stream and publishes a final result upon completion.
The collection involved here is the collection of elements in the stream, so a "collection over time", same is true for the reduce function in AsyncSequence. The job done by the reduce function is to collect the values (and return them). This is (both) not done by the Reducer in TCA, it doesn't collect anything. It is just the "closure" (mentioned at the beginning of that sentence) that a real reducer would apply.
If you think of the "reducer" as the trailing closure and not the full signature of reduce , then you can think of the Store initializer as similar to the kicking-off point of the reduce function, where initial state is needed.
This is exactly how I think of the Store and the Reducer and why I think it's wrong to call the type for the action handling closure a Reducer, because it's not one. The Store and the Reducer combined could be called a reducer, that I agree on. But it's confusing then to name only a part the "Reducer".
The same (refers to "There's no concept of "completion" involved.") can be said for a Combine publisher or async sequence that uses reduce and never completes.
Are you sure about that? I have never used Combines or AsyncSequences reduce function, but from the documentation example and also the documentation of the method (I quoted above), it seems to actually do return with a final result:
let numbers = (0...10)
cancellable = numbers.publisher
.reduce(0, { accum, next in accum + next })
.sink { print("\($0)") } // << here, the `$0` is the final result
// Prints: "55"
Am I missing something here regarding not returning the final result? Of course it doesn't directly return the result (so it's result type is not an Int but another publisher), but the sink will receive the final result and this is the closest to the concept of "returning" in the Combine world. I don't see where the final result is received anywhere with the Reducer though. Yes, the Reducer returns another Effect, but I don't get how an Effect ever emits something like a "final result". If anything, then an accumulated result is received in the view which automatically subscribes to changes in state through the Store. Without Store though, the Reducer is not a full reducer, at least to me.
@Max_Desiatov Comparing the naming of Reducer to that of String or Integer isn't a fair one, I think. Because String and Integer are entirely new names (maybe inspired by things outside of programming) whereas Reducer is inspired by the reduce function and therefore I expect it to behave similar to it for the sake of consistency, which is exactly what I think is not the case here. If there was a stringify method before naming a CharacterSequence and String was chosen due to its similarity to stringify, then the naming situation would be comparable, but I assume we had String before anything like stringify.
I don't know why it was named Reducer in other languages, maybe they don't have (the same) notion of a reduce function, but having the reduce function in Swift I feel like this specific name creates more confusion and inconsistency than it needs to.