4 ms·
If all the Option-handling that process_item() is doing is mapping None to None, is there any good reason for it to be Option-aware at all? fn process_item(i
by nemetroid 6y ago
If all the Option-handling that process_item() is doing is mapping None to None, is there any good reason for it to be Option-aware at all?
fn process_item(input: Item) -> Item {
input.value += 3;
input
}
if let Some(item) = get_item().map(process_item) {
println!("Success, item is {}", item);
}
fn get_item() -> Option<Item> {
if /* success */ {
let new_item = Item {};
return Some(new_item);
}
return None;
}
- eecc 6y agoTo be honest the point of Option<T> isn’t just the pattern match but its underlying functor nature