use crate::node;
use gantz_ca::CaHash;
use gantz_nodetag::NodeTag;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Deserialize, Serialize, CaHash, NodeTag)]
#[cahash("gantz.apply")]
pub struct Apply;
impl node::Node for Apply {
fn n_inputs(&self, _ctx: node::MetaCtx) -> usize {
2
}
fn n_outputs(&self, _ctx: node::MetaCtx) -> usize {
1
}
fn expr(&self, ctx: node::ExprCtx<'_, '_>) -> node::ExprResult {
let inputs = ctx.inputs();
let function = inputs.get(0).and_then(|opt| opt.as_ref());
let arguments = inputs.get(1).and_then(|opt| opt.as_ref());
let args = arguments.map_or("'()", |s| &s[..]);
let expr = function
.map(|f| format!("(apply {f} {args})"))
.unwrap_or_else(|| "'()".to_string());
node::parse_expr(&expr)
}
}