diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index fbb9fd507..770dfe5ba 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -577,12 +577,13 @@ mod pure_builtins { let re = regex.to_str()?; let re: Regex = Regex::new(&format!("^{}$", re.as_str())).unwrap(); match re.captures(&s) { - Some(caps) => Ok(caps - .iter() - .skip(1) - .map(|grp| grp.map(|g| Value::from(g.as_str())).unwrap_or(Value::Null)) - .collect::>() - .into()), + Some(caps) => Ok(Value::List( + caps.iter() + .skip(1) + .map(|grp| grp.map(|g| Value::from(g.as_str())).unwrap_or(Value::Null)) + .collect::>() + .into(), + )), None => Ok(Value::Null), } } @@ -618,21 +619,24 @@ mod pure_builtins { } #[builtin("partition")] fn builtin_partition(vm: &mut VM, pred: Value, list: Value) -> Result { - let mut right: Vec = vec![]; - let mut wrong: Vec = vec![]; + let mut right: imbl::Vector = Default::default(); + let mut wrong: imbl::Vector = Default::default(); let list: NixList = list.to_list()?; for elem in list { let result = vm.call_with(&pred, [elem.clone()])?; if result.force(vm)?.as_bool()? { - right.push(elem); + right.push_back(elem); } else { - wrong.push(elem); + wrong.push_back(elem); }; } - let res = [("right", right), ("wrong", wrong)]; + let res = [ + ("right", Value::List(NixList::from(right))), + ("wrong", Value::List(NixList::from(wrong))), + ]; Ok(Value::attrs(NixAttrs::from_iter(res.into_iter()))) } diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs index b5585923a..49ab62fd1 100644 --- a/tvix/eval/src/value/mod.rs +++ b/tvix/eval/src/value/mod.rs @@ -542,12 +542,6 @@ impl From for Value { } } -impl From> for Value { - fn from(val: Vec) -> Self { - Self::List(NixList::from_vec(val)) - } -} - impl TryFrom for Value { type Error = ErrorKind; @@ -568,11 +562,12 @@ impl TryFrom for Value { } } serde_json::Value::String(s) => Ok(s.into()), - serde_json::Value::Array(a) => Ok(a - .into_iter() - .map(Value::try_from) - .collect::, _>>()? - .into()), + serde_json::Value::Array(a) => Ok(Value::List( + a.into_iter() + .map(Value::try_from) + .collect::, _>>()? + .into(), + )), serde_json::Value::Object(obj) => { match (obj.len(), obj.get("name"), obj.get("value")) { (2, Some(name), Some(value)) => Ok(Self::attrs(NixAttrs::from_kv(