about summary refs log tree commit diff
path: root/tvix/eval/src/value
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/value')
-rw-r--r--tvix/eval/src/value/list.rs4
-rw-r--r--tvix/eval/src/value/mod.rs11
2 files changed, 15 insertions, 0 deletions
diff --git a/tvix/eval/src/value/list.rs b/tvix/eval/src/value/list.rs
index b8682a5b3d5a..da86fdda26ec 100644
--- a/tvix/eval/src/value/list.rs
+++ b/tvix/eval/src/value/list.rs
@@ -28,6 +28,10 @@ impl NixList {
         lhs
     }
 
+    pub fn len(&self) -> usize {
+        self.0.len()
+    }
+
     pub fn construct(count: usize, stack_slice: Vec<Value>) -> Self {
         debug_assert!(
             count == stack_slice.len(),
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),