Not the same logic. This when value is null this makes the function return Some(null) instead of None. Changing map to flatMap is the solution.