Why Enum.flat_map_reduce/3 can halt enum process, but map_reduce/3 can not?

Is there an inconsistency ?

1 Like

Enum.map cannot because you wouldn’t know if a halt command would be the thing you wanted to emit. Map_reduce could, I suppose, but it would make the API more complicated.


oh I see. I edited title to only compare Enum.flat_map_reduce/3 and Enum.map_reduce/3.
I think it do make the API more complicated because functionality of map_reduce/3 can be covered by flat_map_reduce/3.

1 Like

Right. I think the apis are well designed:. Especially as a beginner you’re reaching out for map, a lot – so it’s good that it’s braindead easy. Then as you get better, you might be doing more reduces, which is slightly more complicated but the API is easy enough that you are unlikely to mess it up even if you don’t think about it too hard. Rarely you might reach for map_reduce, and you’d probably almost never use flat_map_reduce (but when you do, you know what you’re doing and it really does need to be there so you’ll tolerate a more tricky API)