Function canrun::goals::project::project_2

source ·
pub fn project_2<A, IA, B, IB, F>(a: IA, b: IB, func: F) -> Project2<A, B>where
    A: Unify,
    IA: Into<Value<A>>,
    B: Unify,
    IB: Into<Value<B>>,
    F: Fn(Rc<A>, Rc<B>) -> Box<dyn Goal> + 'static,
Expand description

Create a projection goal that allows creating a new goal based on the resolved values.

use canrun::{LVar, Query};
use canrun::goals::{project_2, all, both, unify, Succeed, Fail};

let (x, y) = (LVar::new(), LVar::new());
let goal = all![
    unify(1, x),
    unify(2, y),
    project_2(x, y, |x, y| if x < y { Box::new(Succeed) } else { Box::new(Fail) }),
];
let result: Vec<_> = goal.query((x, y)).collect();
assert_eq!(result, vec![(1, 2)])