Solved exercise 21 : implementing flatMap