Is there a way to avoid if-let hell?
Say I have a lot of optional values that I need to unwrap in order to execute some final function. It looks like this:
if let Some(a) = s1.a {
if let Some(b) = s2.b(a) {
if let Some(c) = s3.c() {
my_func(a,b,c);
}
}
}
This goes for n values that need to be unwrapped, creating a hugely indented function call. If you switch to a functional style the results are similar:
s1.a.map(|a|
s2.b(a).map(|b|
s3.c().map(|c|
my_func(a,b,c)
)
)
);
Is there a way to avoid this? From what I've read it looks like this would be a good place to use monads or functors (maybe this requires higher-kinded types?), but I don't know enough to be sure.