From 91456c3520a03e0f3b73224f1d80c56a5392fe32 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sun, 12 Nov 2023 05:45:30 -0800 Subject: refactor(tvix/eval): vm::add_values(): be less verbose Change-Id: Icf328649fd70bdf0fc3ba6cd7754ae29735f11f7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10035 Autosubmit: Adam Joseph Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/vm/mod.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'tvix/eval/src/vm') diff --git a/tvix/eval/src/vm/mod.rs b/tvix/eval/src/vm/mod.rs index 5b9aecb8d440..fd71dbacf480 100644 --- a/tvix/eval/src/vm/mod.rs +++ b/tvix/eval/src/vm/mod.rs @@ -1214,18 +1214,14 @@ async fn add_values(co: GenCo, a: Value, b: Value) -> Result { } } (Value::String(s1), Value::String(s2)) => Value::String(s1.concat(&s2)), - (Value::String(s1), v) => Value::String( - match generators::request_string_coerce(&co, v, CoercionKind::Weak).await { - Ok(s2) => s1.concat(&s2), - Err(c) => return Ok(Value::Catchable(c)), - }, - ), - (v, Value::String(s2)) => Value::String( - match generators::request_string_coerce(&co, v, CoercionKind::Weak).await { - Ok(s1) => s1.concat(&s2), - Err(c) => return Ok(Value::Catchable(c)), - }, - ), + (Value::String(s1), v) => generators::request_string_coerce(&co, v, CoercionKind::Weak) + .await + .map(|s2| Value::String(s1.concat(&s2))) + .into(), + (v, Value::String(s2)) => generators::request_string_coerce(&co, v, CoercionKind::Weak) + .await + .map(|s1| Value::String(s1.concat(&s2))) + .into(), (a, b) => arithmetic_op!(&a, &b, +)?, }; -- cgit 1.4.1