use std::fmt::Debug;
use itertools::Itertools;
use super::State;
use crate::{
core::{LVar, VarId},
resolve_any, AnyVal,
};
#[derive(Debug)]
pub struct LVarList(pub(crate) Vec<VarId>);
impl LVarList {
pub fn one<A>(a: &LVar<A>) -> Self {
LVarList(vec![a.id])
}
pub fn two<A, B>(a: &LVar<A>, b: &LVar<B>) -> Self {
LVarList(vec![a.id, b.id])
}
#[must_use]
pub fn without_resolved_in(&self, state: &State) -> LVarList {
LVarList(
self.0
.iter()
.filter_map(|id| {
if resolve_any(&state.values, &AnyVal::Var(*id)).is_resolved() {
None
} else {
Some(*id)
}
})
.collect(),
)
}
pub fn len(&self) -> usize {
self.0.len()
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub fn flatten(lists: impl Iterator<Item = LVarList>) -> LVarList {
LVarList(lists.flat_map(|list| list.0.into_iter()).unique().collect())
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_lvarlist_len() {
assert_eq!(LVarList(vec![]).len(), 0);
assert_eq!(LVarList(vec![1]).len(), 1);
}
}