Reimplement sort

This commit is contained in:
Jeff 2023-08-25 10:58:32 -04:00
parent 46e2057b1c
commit 491dd649cd
2 changed files with 29 additions and 29 deletions

View File

@ -4,6 +4,35 @@
use crate::{Error, Result, Table, Tool, ToolInfo, Value, ValueType, VariableMap}; use crate::{Error, Result, Table, Tool, ToolInfo, Value, ValueType, VariableMap};
pub struct Sort;
impl Tool for Sort {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "sort",
description: "Apply default ordering to a list or table.",
group: "collections",
inputs: vec![ValueType::List, ValueType::Table],
}
}
fn run(&self, argument: &Value) -> Result<Value> {
if let Ok(mut list) = argument.as_list().cloned() {
list.sort();
Ok(Value::List(list))
} else if let Ok(mut table) = argument.as_table().cloned() {
table.sort();
Ok(Value::Table(table))
} else {
Err(crate::Error::ExpectedList {
actual: argument.clone(),
})
}
}
}
pub struct Transform; pub struct Transform;
impl Tool for Transform { impl Tool for Transform {

View File

@ -168,35 +168,6 @@ pub struct ToolInfo<'a> {
// } // }
// } // }
// pub struct Sort;
// impl Macro for Sort {
// fn info(&self) -> MacroInfo<'static> {
// MacroInfo {
// identifier: "sort",
// description: "Apply default ordering.",
// }
// }
// fn run(&self, argument: &Value) -> Result<Value> {
// if let Ok(mut list) = argument.as_list().cloned() {
// list.sort();
// Ok(Value::List(list))
// } else if let Ok(map) = argument.as_map().cloned() {
// Ok(Value::Map(map))
// } else if let Ok(mut table) = argument.as_table().cloned() {
// table.sort();
// Ok(Value::Table(table))
// } else {
// Err(crate::Error::ExpectedList {
// actual: argument.clone(),
// })
// }
// }
// }
// pub struct Map; // pub struct Map;
// impl Macro for Map { // impl Macro for Map {