It is preferrable not to use expressions with side effects in monadic transformations (map, flatMap and filter). Consider to move them to a separate foreach pass.