Skip to content

Commit

Permalink
Types: Split sum and product
Browse files Browse the repository at this point in the history
We assert that the type is a sum / product and access its children at
the same time. This is more precise than using split.
  • Loading branch information
uncomputable committed Nov 26, 2023
1 parent d2099b2 commit 6b46ce7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/types/final_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,22 @@ impl Final {
}
}
}

/// Return both children, if the type is a sum type
pub fn split_sum(&self) -> Option<(Arc<Self>, Arc<Self>)> {
match &self.bound {
CompleteBound::Sum(left, right) => Some((left.clone(), right.clone())),
_ => None,
}
}

/// Return both children, if the type is a product type
pub fn split_product(&self) -> Option<(Arc<Self>, Arc<Self>)> {
match &self.bound {
CompleteBound::Product(left, right) => Some((left.clone(), right.clone())),
_ => None,
}
}
}

#[cfg(test)]
Expand Down

0 comments on commit 6b46ce7

Please sign in to comment.