about summary refs log tree commit diff
path: root/tvix/eval/src/value/mod.rs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2022-08-30T00·33-0700
committertazjin <tazjin@tvl.su>2022-09-07T20·56+0000
commit197fe37daef242596900bcab948d6fc14348f910 (patch)
treeae7daee7509d03cd2b18fbc2aa16a61dc28f35f6 /tvix/eval/src/value/mod.rs
parent15e2bc54f1beab0f99a7d7199af92a3139052302 (diff)
feat(tvix/eval): Support builtins.length r/4740
Get the length of a list

Change-Id: I41d91e96d833269541a1b3c23b7cc879f96d1e5a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6407
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/value/mod.rs')
-rw-r--r--tvix/eval/src/value/mod.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs
index c5565e6176b3..a8bfc164cdf9 100644
--- a/tvix/eval/src/value/mod.rs
+++ b/tvix/eval/src/value/mod.rs
@@ -103,6 +103,17 @@ impl Value {
         }
     }
 
+    pub fn as_list(&self) -> EvalResult<&NixList> {
+        match self {
+            Value::List(xs) => Ok(xs),
+            other => Err(ErrorKind::TypeError {
+                expected: "list",
+                actual: other.type_of(),
+            }
+            .into()),
+        }
+    }
+
     pub fn to_string(self) -> EvalResult<NixString> {
         match self {
             Value::String(s) => Ok(s),