[][src]Function canrun::goals::project::map_2

pub fn map_2<'a, A, AV, B, BV, C, CV, D, ABtoC, ACtoB, BCtoA>(
    a: AV,
    b: BV,
    c: CV,
    ab_to_c: ABtoC,
    ac_to_b: ACtoB,
    bc_to_a: BCtoA
) -> Goal<'a, D> where
    A: UnifyIn<'a, D> + Debug + 'a,
    AV: IntoVal<A>,
    B: UnifyIn<'a, D> + Debug + 'a,
    BV: IntoVal<B>,
    C: UnifyIn<'a, D> + Debug + 'a,
    CV: IntoVal<C>,
    D: DomainType<'a, A> + DomainType<'a, B> + DomainType<'a, C>,
    ABtoC: Fn(&A, &B) -> C + 'a,
    ACtoB: Fn(&A, &C) -> B + 'a,
    BCtoA: Fn(&B, &C) -> A + 'a, 

Create a projection goal that allows deriving one resolved value from the other two.

Functions must be provided to derive from any combination of two values. Whichever two are resolved first will be used to derive the other.

use canrun::{Goal, all, unify, var, map_2};
use canrun::example::I32;

let (x, y, z) = (var(), var(), var());
let goal: Goal<I32> = all![
    unify(1, x),
    unify(2, y),
    map_2(x, y, z, |x, y| x + y, |x, z| z - x, |y, z| z - y),
];
let result: Vec<_> = goal.query(z).collect();
assert_eq!(result, vec![3])