From 75de7f7e612e7542be91ca2b4a982acc3ab65966 Mon Sep 17 00:00:00 2001 From: Arthur Targaryen Date: Sat, 9 Oct 2021 19:11:15 +0200 Subject: [PATCH] Implement `PartialOrd` for `Value::Stream` --- crates/nu-protocol/src/value/mod.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index 4b8e6b7948..28e1a173f6 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -479,9 +479,7 @@ impl PartialOrd for Value { (Value::Block { val: b1, .. }, Value::Block { val: b2, .. }) if b1 == b2 => { Some(Ordering::Equal) } - (Value::List { vals: lhs, .. }, Value::List { vals: rhs, .. }) if lhs == rhs => { - Some(Ordering::Equal) - } + (Value::List { vals: lhs, .. }, Value::List { vals: rhs, .. }) => lhs.partial_cmp(rhs), ( Value::Record { vals: lhs, @@ -531,6 +529,18 @@ impl PartialOrd for Value { (Value::Stream { stream: lhs, .. }, Value::Stream { stream: rhs, .. }) => { lhs.clone().partial_cmp(rhs.clone()) } + (Value::Stream { stream: lhs, .. }, Value::String { val: rhs, .. }) => { + lhs.clone().collect_string().partial_cmp(rhs) + } + (Value::String { val: lhs, .. }, Value::Stream { stream: rhs, .. }) => { + lhs.partial_cmp(&rhs.clone().collect_string()) + } + (Value::Stream { stream: lhs, .. }, Value::List { vals: rhs, .. }) => { + lhs.clone().collect::>().partial_cmp(rhs) + } + (Value::List { vals: lhs, .. }, Value::Stream { stream: rhs, .. }) => { + lhs.partial_cmp(&rhs.clone().collect::>()) + } (_, _) => None, } } @@ -846,7 +856,6 @@ impl Value { span, }), (lhs, Value::Stream { stream: rhs, .. }) => Ok(Value::Bool { - // TODO(@arthur-targaryen): Not sure about this clone (see also `Value::not_in`). val: rhs.clone().any(|x| lhs == &x), span, }), @@ -881,7 +890,6 @@ impl Value { span, }), (lhs, Value::Stream { stream: rhs, .. }) => Ok(Value::Bool { - // TODO(@arthur-targaryen): Not sure about this clone (see also `Value::r#in`). val: rhs.clone().all(|x| lhs != &x), span, }),