#![allow(dead_code, unused_variables, unused_imports, unreachable_code, unused_assignments)]
use crate::components::language::var::Var;
use crate::components::language::Lang;
use rpds::Vector;
use std::iter::Sum;
use std::ops::Add;
#[derive(Debug, Clone)]
pub struct VarFunction(Vector<(Var, Lang)>);
impl VarFunction {
pub fn get_bodies(&self, names: &[Var]) -> Vec<Lang> {
todo!();
}
}
impl TryFrom<Lang> for VarFunction {
type Error = String;
fn try_from(value: Lang) -> Result<Self, Self::Error> {
match value {
Lang::Let {
variable,
r#type: _,
expression,
is_public: _,
is_testable: _,
is_export: _,
help_data: _,
} if expression.is_function() => {
let var = Var::try_from(variable).unwrap();
Ok(VarFunction(Vector::new().push_back((var, *expression))))
}
_ => Err("It's not a function declaration".to_string()),
}
}
}
impl Default for VarFunction {
fn default() -> Self {
VarFunction(Vector::new())
}
}
impl Add for VarFunction {
type Output = Self;
fn add(self, other: Self) -> Self {
VarFunction(self.0.iter().chain(other.0.iter()).cloned().collect())
}
}
impl Sum for VarFunction {
fn sum<I: Iterator<Item = VarFunction>>(iter: I) -> Self {
iter.reduce(|x, y| x + y).unwrap_or_default()
}
}