Expand description
Practical extension methods for Rust standard library collections.
Enables direct functional-style collection manipulation without the usual iterator boilerplate.
§Features
- Equivalents of standard iterator methods are added to standard library collections
- Additional utility methods commonly found in collection libraries are also included
- Transformation methods return a new collection instance instead of returning an iterator
- All methods treat collection instances as immutable although some may consume them
- Performance is near optimal and overhead is limited to new collection creation
§Examples
use cantrip::*;
let a = vec![1, 2, 3];
a.fold(0, |r, &x| r + x); // 6
a.filter(|&x| x > 1); // vec![2, 3]
a.map(|x| x + 1); // vec![2, 3, 4]
a.add(1).unique(); // vec![1, 2, 3]
a.delete_at(0).tail(); // vec![3]
a.interleave(vec![4, 5, 6]); // vec![(1, 4, 2, 5, 3, 6)]
a.group_by(|x| x % 2); // HashMap::from([(0, vec![2]), (1, vec![1, 3])])§Methods
Traits§
- Consuming collection operations.
- Conversion into an
Iteratorover references. - List operations.
- Map operations.
- Ordered collection operations.
- Sequence operations.
- Slice operations.
- Traversable collection operations.