use super::{Function, Kind, macros, of_library};
use crate::cel::Type;
use crate::cel::functions::Function as CelFunction;
use crate::cel::library::Library;
#[must_use]
pub fn of_type(ty: &Type) -> Vec<Function> {
let methods = CelFunction::ALL
.iter()
.copied()
.filter(|function| {
function.definition().overloads.iter().any(|overload| {
overload
.receiver
.is_some_and(|receiver| receiver.takes_type(ty))
})
})
.map(|function| of_library(function, Kind::Cel));
let ranged = matches!(
ty.cel(),
Type::List(_) | Type::Map(..) | Type::Record(_) | Type::Dyn
);
let optional = matches!(ty.cel(), Type::Optional(_) | Type::Dyn);
let comprehensions = ranged
.then(|| macros::comprehensions(false))
.into_iter()
.chain(optional.then(|| macros::comprehensions(true)))
.flatten();
methods.chain(comprehensions).collect()
}