Skip to content

Commit

Permalink
Add string multiplication
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-m-2983 committed Aug 24, 2024
1 parent 576ffe0 commit e42770b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/types/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e42770b

Please sign in to comment.