diff --git a/examples/fetch.ds b/examples/fetch.ds index 078ec11..b5ebd57 100644 --- a/examples/fetch.ds +++ b/examples/fetch.ds @@ -1,4 +1,8 @@ raw_data = (download "https://api.sampleapis.com/futurama/cast") -dust_data = (from_json raw_data) +cast_data = (from_json raw_data) -(assert_equal "Billy West", dust_data.0.name) +names = transform cast_member in cast_data { + cast_member.name +} + +(assert_equal "Billy West", names.0) diff --git a/src/abstract_tree/for.rs b/src/abstract_tree/for.rs index 91c9470..cefd260 100644 --- a/src/abstract_tree/for.rs +++ b/src/abstract_tree/for.rs @@ -32,12 +32,19 @@ impl AbstractTree for For { let value = self.expression.run(source, context)?; let list = value.as_list()?; let key = self.identifier.inner(); - let mut context = context.clone(); + + let original_value = context.get_value(key)?; for value in list { context.set_value(key.clone(), value.clone())?; - self.item.run(source, &mut context)?; + self.item.run(source, context)?; + } + + if let Some(original_value) = original_value { + context.set_value(key.clone(), original_value)?; + } else { + context.set_value(key.clone(), Value::Empty)?; } Ok(Value::Empty) diff --git a/src/value/mod.rs b/src/value/mod.rs index fbc7b41..5216050 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -320,6 +320,7 @@ impl AddAssign for Value { (Value::Integer(left), Value::Integer(right)) => *left += right, (Value::Float(left), Value::Float(right)) => *left += right, (Value::Float(left), Value::Integer(right)) => *left += right as f64, + (Value::String(left), Value::String(right)) => *left += &right, _ => {} } }