nicer iteration

This commit is contained in:
Niko Abeler 2022-11-23 20:26:57 +01:00
parent 0a548bbd32
commit b6ab0f2144
1 changed files with 7 additions and 0 deletions

View File

@ -36,6 +36,13 @@ fn layout_from_edge_list(
let mut edge_matrix = graph::new_edge_matrix(number_of_nodes); let mut edge_matrix = graph::new_edge_matrix(number_of_nodes);
match edges.extract::<&PyIterator>() { match edges.extract::<&PyIterator>() {
Ok(iter) => { Ok(iter) => {
iter.iter()?
.map(|edge| edge.and_then(PyAny::extract::<(usize, usize)>))
.for_each(|edge| {
if let Ok((u, v)) = edge {
graph::add_edge(&mut edge_matrix, u, v);
}
});
for edge in iter { for edge in iter {
let edge = edge?; let edge = edge?;
let edge = edge.extract::<(usize, usize)>()?; let edge = edge.extract::<(usize, usize)>()?;