canrun::collections::lvec

Function get

Source
pub fn get<T, IntoT, Index, Collection>(
    item: IntoT,
    index: Index,
    collection: Collection,
) -> Get<T>
where T: Unify, IntoT: Into<Value<T>>, Index: Into<Value<usize>>, Collection: Into<Value<LVec<T>>>,
Expand description

Create a Goal that attempts to unify a Value<T> with the item at a specific index in a LVec<T>.

ยงExamples:

use canrun::{LVar, all, unify, lvec, Query};

let needle = LVar::new();
let index = LVar::new();
let haystack = LVar::new();
let goal = all![
    unify(index, 0),
    unify(&haystack, lvec![1, 2, 3]),
    lvec::get(needle, index, haystack),
];
let results: Vec<_> = goal.query(needle).collect();
assert_eq!(results, vec![1]);