Skip to content

Commit 6cdd6b9

Browse files
committed
Handle empty lists
1 parent 7fa81c5 commit 6cdd6b9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

api/src/helpers/lca_helper.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ pub fn calculate_lca(
2222
let species_index = get_species_index(version);
2323

2424
for rank in (0..amount_of_ranks).rev() {
25-
2625
let mut iterator = lineages
2726
.iter()
2827
.map(|x| x[rank as usize])
2928
.filter(|&x| if rank == genus_index || rank == species_index { x > 0 } else { x >= 0 });
3029

3130
// Check if all elements in the iterator are the same
32-
let first = iterator.next().unwrap();
33-
if first > 0 && iterator.all(|item| item == first) {
34-
return first;
31+
if let Some(first) = iterator.next() {
32+
if first > 0 && iterator.all(|item| item == first) {
33+
return first;
34+
}
3535
}
3636
}
3737

0 commit comments

Comments
 (0)