From 6b46ce7b2f885f91e7be87d5443a01505839f61f Mon Sep 17 00:00:00 2001 From: Christian Lewe <ch_lewe@agdsn.me> Date: Sat, 25 Nov 2023 21:26:23 +0100 Subject: [PATCH] Types: Split sum and product We assert that the type is a sum / product and access its children at the same time. This is more precise than using split. --- src/types/final_data.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/types/final_data.rs b/src/types/final_data.rs index 07cbbf82..0667785d 100644 --- a/src/types/final_data.rs +++ b/src/types/final_data.rs @@ -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)]