macro_rules! any { ($($item:expr),* $(,)?) => { ... }; }
Expand description
Create a goal that yields a state for every successful sub-goal.
This is essentially an “OR” operation on a vector of goals. It may yield from zero to as many resolved states as there are sub-goals.
Examples
Each successful goal will yield a different result:
use canrun::{any, unify, LVar, Query};
let x = LVar::new();
let goal = any![unify(x, 1), unify(x, 2), unify(x, 3)];
let result: Vec<_> = goal.query(x).collect();
assert_eq!(result, vec![1, 2, 3])
One failing goal will not cause the other to fail:
let goal = any!(unify(1, 2), unify(x, 2), unify(x, 3));
let result: Vec<_> = goal.query(x).collect();
assert_eq!(result, vec![2, 3])
All goals can fail, leading to no results:
let goal = any!(unify(6, 5), unify(42, 0), unify(1, 2));
let result: Vec<_> = goal.query(x).collect();
assert_eq!(result, vec![]) // Empty result