mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
port empty command (#528)
* port empty command * Pull upstream and use test_data() function for example tests
This commit is contained in:
@ -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 }
|
||||
|
Reference in New Issue
Block a user