Function canrun::collections::lvec::member
source · pub fn member<T, IntoT, IntoLVecT>(
item: IntoT,
collection: IntoLVecT
) -> Member<T>where
T: Unify,
IntoT: Into<Value<T>>,
IntoLVecT: Into<Value<LVec<T>>>,
Expand description
Create a Goal
that attempts to unify a Value<T>
with
any of the items in a LVec<T>
.
This goal will fork the state for each match found.
Examples:
use canrun::{LVar, all, unify, lvec, Query};
let x = LVar::new();
let xs = LVar::new();
let goal = all![
unify(&x, 1),
unify(&xs, lvec![1, 2, 3]),
lvec::member(x, xs),
];
let results: Vec<_> = goal.query(x).collect();
assert_eq!(results, vec![1]);
let x = LVar::new();
let goal = all![
lvec::member(x, lvec![1, 2, 3]),
];
let results: Vec<_> = goal.query(x).collect();
assert_eq!(results, vec![1, 2, 3]);