From 75a22321ce55512d5f436168a2f913cf9f8f8ee3 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 11 Aug 2022 11:50:38 +0300 Subject: feat(tvix/eval): implement list concatenation Change-Id: Icdf715d116371a9f139bdf95266410bf967bef25 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6144 Reviewed-by: sterni Tested-by: BuildkiteCI --- tvix/eval/src/value/list.rs | 9 +++++++++ tvix/eval/src/value/mod.rs | 10 ++++++++++ 2 files changed, 19 insertions(+) (limited to 'tvix/eval/src/value') diff --git a/tvix/eval/src/value/list.rs b/tvix/eval/src/value/list.rs index d5f7c8b2ba44..f9d85229410a 100644 --- a/tvix/eval/src/value/list.rs +++ b/tvix/eval/src/value/list.rs @@ -18,3 +18,12 @@ impl Display for NixList { f.write_str("]") } } + +impl NixList { + pub fn concat(&self, other: &Self) -> Self { + let mut lhs = self.clone(); + let mut rhs = other.clone(); + lhs.0.append(&mut rhs.0); + lhs + } +} diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs index 2a89f1c35890..0c9042dbfe25 100644 --- a/tvix/eval/src/value/mod.rs +++ b/tvix/eval/src/value/mod.rs @@ -81,6 +81,16 @@ impl Value { }), } } + + pub fn as_list(self) -> EvalResult { + match self { + Value::List(l) => Ok(l), + other => Err(Error::TypeError { + expected: "list", + actual: other.type_of(), + }), + } + } } impl Display for Value { -- cgit 1.4.1