port empty command (#528)

* port empty command

* Pull upstream and use test_data() function for example tests
This commit is contained in:
Ștefan
2021-12-19 20:11:57 +01:00
committed by GitHub
parent 038ad951da
commit c37bdcd119
4 changed files with 253 additions and 0 deletions

View File

@ -463,6 +463,21 @@ impl Value {
}
}
/// Check if the content is empty
pub fn is_empty(self) -> bool {
match self {
Value::String { val, .. } => val.is_empty(),
Value::List { vals, .. } => {
vals.is_empty() && vals.iter().all(|v| v.clone().is_empty())
}
Value::Record { cols, vals, .. } => {
cols.iter().all(|v| v.is_empty()) && vals.iter().all(|v| v.clone().is_empty())
}
Value::Nothing { .. } => true,
_ => false,
}
}
/// Create a new `Nothing` value
pub fn nothing(span: Span) -> Value {
Value::Nothing { span }