diff options
Diffstat (limited to 'tvix')
-rw-r--r-- | tvix/eval/src/builtins/mod.rs | 2 | ||||
-rw-r--r-- | tvix/eval/src/value/attrs.rs | 8 | ||||
-rw-r--r-- | tvix/eval/src/value/list.rs | 4 |
3 files changed, 13 insertions, 1 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 331dcbcd419c..b93bbd99f87a 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -898,7 +898,7 @@ mod pure_builtins { fn builtin_tail(_: &mut VM, list: Value) -> Result<Value, ErrorKind> { let xs = list.to_list()?; - if xs.len() == 0 { + if xs.is_empty() { Err(ErrorKind::TailEmptyList) } else { let output = xs.into_iter().skip(1).collect::<Vec<_>>(); diff --git a/tvix/eval/src/value/attrs.rs b/tvix/eval/src/value/attrs.rs index d413f0073f26..6515fb515a5d 100644 --- a/tvix/eval/src/value/attrs.rs +++ b/tvix/eval/src/value/attrs.rs @@ -301,6 +301,14 @@ impl NixAttrs { } } + pub fn is_empty(&self) -> bool { + match &self.0 { + AttrsRep::Im(map) => map.is_empty(), + AttrsRep::Empty => true, + AttrsRep::KV { .. } => false, + } + } + /// Select a value from an attribute set by key. pub fn select(&self, key: &str) -> Option<&Value> { self.0.select(key) diff --git a/tvix/eval/src/value/list.rs b/tvix/eval/src/value/list.rs index 70952419abea..6d830b7283d0 100644 --- a/tvix/eval/src/value/list.rs +++ b/tvix/eval/src/value/list.rs @@ -67,6 +67,10 @@ impl NixList { self.0.get(i) } + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } + pub fn construct(count: usize, stack_slice: Vec<Value>) -> Self { debug_assert!( count == stack_slice.len(), |