Intermediate Rust
Q100 / 100

What is the difference between map() and and_then() on Option/Result?

Correct! Well done.

Incorrect.

The correct answer is B) map() transforms the inner value, wrapping the result back; and_then() (flatMap) passes the inner value to a closure that returns Option/Result itself, avoiding double wrapping

B

Correct Answer

map() transforms the inner value, wrapping the result back; and_then() (flatMap) passes the inner value to a closure that returns Option/Result itself, avoiding double wrapping

Explanation

opt.map(|x| x + 1) returns Option<i32>. opt.and_then(|x| if x > 0 { Some(x) } else { None }) flattens Option<Option<i32>> into Option<i32>.

Progress
100/100