Function canrun::goals::project::map_1

source ·
pub fn map_1<A, AV, B, BV, AtoB, BtoA>(
    a: AV,
    b: BV,
    a_to_b: AtoB,
    b_to_a: BtoA
) -> Map1<A, B>where
    A: Unify,
    B: Unify,
    AV: Into<Value<A>>,
    BV: Into<Value<B>>,
    AtoB: Fn(&A) -> B + 'static,
    BtoA: Fn(&B) -> A + 'static,
Expand description

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

Functions must be provided to derive in both directions. Whichever value is resolved first will be used to derive the other.

use canrun::{LVar, Query};
use canrun::goals::{map_1, all, unify};

let (x, y) = (LVar::new(), LVar::new());
let goal = all![
    unify(1, x),
    map_1(x, y, |x| x + 1, |y| y - 1),
];
let result: Vec<_> = goal.query(y).collect();
assert_eq!(result, vec![2])