flatMap and pattern matching