mapAccum package:conduino

Map a pure "stateful" function over each incoming item. Give a function to update the state and return an output and an initial state.