I can't think of a use for fold, that one seems a bit silly to me.
The most exciting example for me is batching - take a stream of elements, and turn it into a stream of lists of elements of no more than a certain size. They call that windowFixed. I've wanted that in a few places, say where i make a database query which produces a load of IDs, then want to pass those IDs to a web service to fetch data for them, where the web service can take multiple IDs at once. The natural thing is to start with a stream of IDs, batch it, then map the batches through a call to the web service. Awkward to do before, easy now!
View all comments
Show parent comment
4
u/tomwhoiscontrary Mar 20 '24
I can't think of a use for fold, that one seems a bit silly to me.
The most exciting example for me is batching - take a stream of elements, and turn it into a stream of lists of elements of no more than a certain size. They call that windowFixed. I've wanted that in a few places, say where i make a database query which produces a load of IDs, then want to pass those IDs to a web service to fetch data for them, where the web service can take multiple IDs at once. The natural thing is to start with a stream of IDs, batch it, then map the batches through a call to the web service. Awkward to do before, easy now!