Replace map(unwrap()) with fold()
This commit is contained in:
parent
41bf063a71
commit
5935d43f09
1 changed files with 15 additions and 8 deletions
|
@ -138,14 +138,21 @@ fn add_foreign_link(target: &mut Entry, from: StoreId) -> Result<()> {
|
||||||
target.get_internal_links()
|
target.get_internal_links()
|
||||||
.and_then(|mut links| {
|
.and_then(|mut links| {
|
||||||
links.push(from);
|
links.push(from);
|
||||||
let links = links_into_values(links);
|
let links = try!(links_into_values(links)
|
||||||
if links.iter().any(|o| o.is_none()) {
|
.into_iter()
|
||||||
Err(LEK::InternalConversionError.into())
|
.fold(Ok(vec![]), |acc, elem| {
|
||||||
} else {
|
acc.and_then(move |mut v| {
|
||||||
let links = links.into_iter().map(|opt| opt.unwrap()).collect();
|
match elem {
|
||||||
|
None => Err(LEK::InternalConversionError.into()),
|
||||||
|
Some(e) => {
|
||||||
|
v.push(e);
|
||||||
|
Ok(v)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}));
|
||||||
process_rw_result(target.get_header_mut().set("imag.links", Value::Array(links)))
|
process_rw_result(target.get_header_mut().set("imag.links", Value::Array(links)))
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue