chapter 4 from scala book