From e42770b1061b1d79bcfa41e82d26cad1a23a8e41 Mon Sep 17 00:00:00 2001 From: michael-m-2983 Date: Fri, 23 Aug 2024 22:17:19 -0500 Subject: [PATCH] Add string multiplication --- src/types/ops.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/types/ops.rs b/src/types/ops.rs index cf30df3..03d019f 100644 --- a/src/types/ops.rs +++ b/src/types/ops.rs @@ -43,6 +43,14 @@ impl Type { return Ok(Self::Float(a * b)); } + if let (Self::String(a), Self::Float(b)) = (self, other) { + return Ok(Self::String(a.repeat((*b) as usize))); + } + + if let (Self::Float(a), Self::String(b)) = (self, other) { + return Ok(Self::String(b.repeat((*a) as usize))); + } + Err(( "Operator '*' can only be applied to numbers.".into(), ErrorType::TypeError,