use crate::{ty::*, value::*};
use derive_more::{Deref, DerefMut};
#[derive(Clone, Default, Deref, DerefMut)]
pub struct ValueList(Vec<Value>);
impl ValueList {
pub fn new(list: Vec<Value>) -> Self {
Self(list)
}
pub fn types(&self) -> TypeList {
TypeList::new(
self.0
.iter()
.map(|v| v.ty())
.collect::<Vec<Type>>()
.into_iter()
.collect(),
)
}
}
impl IntoIterator for ValueList {
type Item = Value;
type IntoIter = std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl PartialEq for ValueList {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl std::iter::FromIterator<Value> for ValueList {
fn from_iter<T: IntoIterator<Item = Value>>(iter: T) -> Self {
let vec = Vec::from_iter(iter);
ValueList(vec)
}
}
impl std::fmt::Debug for ValueList {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
self.iter()
.map(|value| format!("{value}"))
.collect::<Vec<_>>()
.join(", ")
)
}
}