pub fn project_1<A, IA, F>(a: IA, func: F) -> Project1<A>where
A: Unify,
IA: Into<Value<A>>,
F: Fn(Rc<A>) -> Box<dyn Goal> + 'static,
Expand description
Create a projection goal that allows creating a new goal based on the resolved value.
use canrun::{LVar, Query};
use canrun::goals::{project_1, both, unify, Succeed, Fail};
let x = LVar::new();
let goal = both(unify(1, x), project_1(x, |x| if *x < 2 { Box::new(Succeed) } else { Box::new(Fail) }));
let result: Vec<_> = goal.query(x).collect();
assert_eq!(result, vec![1])