Stateful fold

![image](https://cloud.githubusercontent.com/assets/4955075/4498261/20a75068-4a77-11e4-85ec-de3c2b330dcb.png)