Closed Raynos closed 11 years ago
I'm not convinced on forEach
, at least not for reducers, because of following reasons:
reducibles
, that is any operation except reduce
just composes lazy transformation
over given input. Only thing that triggers transformation flow is reduce
. This makes it very simple to understand
and reason.forEach
implies synchronous operation and embraces state changes to things in the outer scope. Later is fine
as long as it's just endpoint doing IO (including rendering etc...). But I think it's just too easy to misuse and expect
that average js dev will do that.Note that reduce
is different as it encourages accumulative transformations over passed in data, there for there is
much less temptation to mutate things that have not explicitly being passed to it. This also make reducer
functions
more reusable and composable.
That being said, I do understand where you're coming from, and I'm considering fold
which is just like reduce but with argument order inverted, that way fold(sequence, write)
will be equivalent of forEeach
if write
takes only one arg.
@Gozala pipe
triggers transformation flow.
The reason I want forEach
is that i'd use it as a reduce
when I don't want reduce.
reduce(thing, function (_, value) {
/* logic */
})
// vs
forEach(thing, function (value) {
/* logic */
})
I don't mind fold
other then i really don't know what the difference between fold
and reduce
is. I understand the semantics of forEach
In 2.0 there is fold
instead of reduce
which also removes a need for forEach
.
https://github.com/Raynos/reflex-todo/blob/master/lib/forEach.js