mirror of
https://github.com/nushell/nushell.git
synced 2025-02-05 21:21:10 +01:00
Refactor in
operator for Range
This commit is contained in:
parent
29cbcb8459
commit
d1f0740765
@ -1020,45 +1020,8 @@ impl Value {
|
|||||||
|
|
||||||
match (self, rhs) {
|
match (self, rhs) {
|
||||||
(lhs, Value::Range { val: rhs, .. }) => Ok(Value::Bool {
|
(lhs, Value::Range { val: rhs, .. }) => Ok(Value::Bool {
|
||||||
val: if matches!(
|
// TODO(@arthur-targaryen): Not sure about this clone.
|
||||||
rhs.incr.gt(
|
val: rhs.clone().into_iter().contains(lhs),
|
||||||
Span::unknown(),
|
|
||||||
&Value::Int {
|
|
||||||
val: 0,
|
|
||||||
span: Span::unknown()
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Ok(Value::Bool { val: true, .. })
|
|
||||||
) {
|
|
||||||
matches!(
|
|
||||||
lhs.gte(Span::unknown(), &rhs.from),
|
|
||||||
Ok(Value::Bool { val: true, .. })
|
|
||||||
) && match rhs.inclusion {
|
|
||||||
RangeInclusion::Inclusive => matches!(
|
|
||||||
lhs.lte(Span::unknown(), &rhs.to),
|
|
||||||
Ok(Value::Bool { val: true, .. })
|
|
||||||
),
|
|
||||||
RangeInclusion::RightExclusive => matches!(
|
|
||||||
lhs.lt(Span::unknown(), &rhs.to),
|
|
||||||
Ok(Value::Bool { val: true, .. })
|
|
||||||
),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
matches!(
|
|
||||||
lhs.lte(Span::unknown(), &rhs.from),
|
|
||||||
Ok(Value::Bool { val: true, .. })
|
|
||||||
) && match rhs.inclusion {
|
|
||||||
RangeInclusion::Inclusive => matches!(
|
|
||||||
lhs.gte(Span::unknown(), &rhs.to),
|
|
||||||
Ok(Value::Bool { val: true, .. })
|
|
||||||
),
|
|
||||||
RangeInclusion::RightExclusive => matches!(
|
|
||||||
lhs.gt(Span::unknown(), &rhs.to),
|
|
||||||
Ok(Value::Bool { val: true, .. })
|
|
||||||
),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
span,
|
span,
|
||||||
}),
|
}),
|
||||||
(Value::String { val: lhs, .. }, Value::String { val: rhs, .. }) => Ok(Value::Bool {
|
(Value::String { val: lhs, .. }, Value::String { val: rhs, .. }) => Ok(Value::Bool {
|
||||||
@ -1079,6 +1042,7 @@ impl Value {
|
|||||||
span,
|
span,
|
||||||
}),
|
}),
|
||||||
(lhs, Value::Stream { stream: rhs, .. }) => Ok(Value::Bool {
|
(lhs, Value::Stream { stream: rhs, .. }) => Ok(Value::Bool {
|
||||||
|
// TODO(@arthur-targaryen): Not sure about this clone too.
|
||||||
val: rhs.clone().any(|x| {
|
val: rhs.clone().any(|x| {
|
||||||
matches!(
|
matches!(
|
||||||
lhs.eq(Span::unknown(), &x),
|
lhs.eq(Span::unknown(), &x),
|
||||||
|
Loading…
Reference in New Issue
Block a user