refactor: type
This commit is contained in:
42
src/ty/internal/list.rs
Normal file
42
src/ty/internal/list.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use derive_more::Constructor;
|
||||
use rpds::VectorSync;
|
||||
|
||||
use crate::ty::public as p;
|
||||
|
||||
use crate::vm::VM;
|
||||
use super::{ToPublic, Value};
|
||||
|
||||
#[derive(Debug, Constructor, Clone, PartialEq)]
|
||||
pub struct List {
|
||||
data: VectorSync<Value>,
|
||||
}
|
||||
|
||||
impl List {
|
||||
pub fn empty() -> List {
|
||||
List {
|
||||
data: VectorSync::new_sync()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push(&mut self, elem: Value) {
|
||||
self.data.push_back_mut(elem);
|
||||
}
|
||||
|
||||
pub fn concat(mut self, other: List) -> List {
|
||||
for elem in other.data.iter() {
|
||||
self.data.push_back_mut(elem.clone());
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl ToPublic for List {
|
||||
fn to_public(self, vm: &VM) -> p::Value {
|
||||
p::Value::List(p::List::new(
|
||||
self.data
|
||||
.iter()
|
||||
.map(|value| value.clone().to_public(vm))
|
||||
.collect(),
|
||||
))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user