A procedural macro to create Iterators over a set defined by Haskell-inspired set-builder notation.
It should be noted that these "sets" are not true sets in the sense that there is no guarantee that the members (elements) of the set are unique.
rs
// The name(s) of the binding(s)
// │
// Mapping │ ┌── Expressions that evaluate into types implementing `IntoIterator`.
// expression │ │
// │ │ │ ┌─ The optional predicate, evaluates to `bool`
// ▼ ▼ ▼ ▼
set! { expr : $(ident <- expr),* $(, expr)? }
This is only provided for mathematical parity and returns arrays rather than Iterators,
array syntax [...]
should always be preferred to this.
It is noteworthy that this will only work with literals. If you wish to use identifiers, please use array syntax instead.
rs
// ┌─ Literal(s) to put in the set
// ▼
set! { $(literal),* }
```rs use set_builder::set;
// Single-binding set with a predicate
let set = set! { x * 2 : x <- [1, 2, 3], *x > 1 };
assert_eq!(set.collect::
// Cartesian product without a predicate
let set = set! { (x, y) : x <- [1, 2], y <- [3, 4] };
assert_eq!(set.collect::
// Simple enumeration let set = set! { 1, 2, 3, 4, 5 }; assert_eq!(set, [1, 2, 3, 4, 5]); ```