mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 10:45:41 +02:00
make ++
append lists (#6766)
* make `++` append lists * fmt * fix for database
This commit is contained in:
@ -47,7 +47,8 @@ impl Expression {
|
||||
| Operator::Equal
|
||||
| Operator::NotEqual
|
||||
| Operator::In
|
||||
| Operator::NotIn => 80,
|
||||
| Operator::NotIn
|
||||
| Operator::Append => 80,
|
||||
Operator::BitAnd => 75,
|
||||
Operator::BitXor => 70,
|
||||
Operator::BitOr => 60,
|
||||
|
@ -14,6 +14,7 @@ pub enum Operator {
|
||||
RegexMatch,
|
||||
NotRegexMatch,
|
||||
Plus,
|
||||
Append,
|
||||
Minus,
|
||||
Multiply,
|
||||
Divide,
|
||||
@ -43,6 +44,7 @@ impl Display for Operator {
|
||||
Operator::RegexMatch => write!(f, "=~"),
|
||||
Operator::NotRegexMatch => write!(f, "!~"),
|
||||
Operator::Plus => write!(f, "+"),
|
||||
Operator::Append => write!(f, "++"),
|
||||
Operator::Minus => write!(f, "-"),
|
||||
Operator::Multiply => write!(f, "*"),
|
||||
Operator::Divide => write!(f, "/"),
|
||||
|
@ -1681,6 +1681,34 @@ impl Value {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn append(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
|
||||
match (self, rhs) {
|
||||
(Value::List { vals: lhs, .. }, Value::List { vals: rhs, .. }) => {
|
||||
let mut lhs = lhs.clone();
|
||||
let mut rhs = rhs.clone();
|
||||
lhs.append(&mut rhs);
|
||||
Ok(Value::List { vals: lhs, span })
|
||||
}
|
||||
(Value::List { vals: lhs, .. }, val) => {
|
||||
let mut lhs = lhs.clone();
|
||||
lhs.push(val.clone());
|
||||
Ok(Value::List { vals: lhs, span })
|
||||
}
|
||||
(val, Value::List { vals: rhs, .. }) => {
|
||||
let mut rhs = rhs.clone();
|
||||
rhs.insert(0, val.clone());
|
||||
Ok(Value::List { vals: rhs, span })
|
||||
}
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: op,
|
||||
lhs_ty: self.get_type(),
|
||||
lhs_span: self.span()?,
|
||||
rhs_ty: rhs.get_type(),
|
||||
rhs_span: rhs.span()?,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sub(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
|
||||
match (self, rhs) {
|
||||
(Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
|
||||
|
Reference in New Issue
Block a user