summaryrefslogtreecommitdiff
path: root/src/eval/ops.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-05-16 15:55:50 +0200
committerLaurenz <laurmaedje@gmail.com>2022-05-16 15:55:50 +0200
commitbc1bc91a33bcef567dbd7f846dbfac9d19a0994e (patch)
tree71d93f60ee34db03755ad10f7c65b30586522821 /src/eval/ops.rs
parent204cad6bd673da1a265b5b6650ebe89c89ddbace (diff)
Allow adding `none` and anything
Diffstat (limited to 'src/eval/ops.rs')
-rw-r--r--src/eval/ops.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/eval/ops.rs b/src/eval/ops.rs
index 57390a65..b3f2f3b4 100644
--- a/src/eval/ops.rs
+++ b/src/eval/ops.rs
@@ -61,6 +61,9 @@ pub fn neg(value: Value) -> StrResult<Value> {
/// Compute the sum of two values.
pub fn add(lhs: Value, rhs: Value) -> StrResult<Value> {
Ok(match (lhs, rhs) {
+ (a, None) => a,
+ (None, b) => b,
+
(Int(a), Int(b)) => Int(a + b),
(Int(a), Float(b)) => Float(a as f64 + b),
(Float(a), Int(b)) => Float(a + b as f64),
@@ -83,9 +86,6 @@ pub fn add(lhs: Value, rhs: Value) -> StrResult<Value> {
(Fraction(a), Fraction(b)) => Fraction(a + b),
(Str(a), Str(b)) => Str(a + b),
-
- (Content(a), None) => Content(a),
- (None, Content(b)) => Content(b),
(Content(a), Content(b)) => Content(a + b),
(Content(a), Str(b)) => Content(a + model::Content::Text(b)),
(Str(a), Content(b)) => Content(model::Content::Text(a) + b),