rust-lodash
A high-performance, type-safe Rust implementation of Lodash collection methods with zero-cost abstractions.
Features
- 🚀 High Performance: Zero-cost abstractions with optimized implementations
- 🔒 Type Safety: Full compile-time type checking and memory safety
- 🔗 Chainable API: Fluent interface for method chaining
- ⚡ Async Support: Optional async/await support for modern Rust
- 🔄 Parallel Processing: Optional parallel iteration with rayon
- 🌐 WASM Compatible: Full WebAssembly support for browser usage
- 📦 No Std Support: Optional
no_stdsupport for embedded systems
Quick Start
Add this to your Cargo.toml:
[]
= "0.1.0"
Basic Usage
use *;
// Basic operations
let doubled = map;
assert_eq!;
// Chainable operations
let result = chain
.filter
.map
.collect;
assert_eq!;
// Collection operations
let numbers = vec!;
let evens = filter;
let sum = reduce;
Advanced Features
Async Support (Optional)
[]
= { = "0.1.0", = ["async"] }
use *;
// Async operations (requires async feature)
// let async_result = map_async(&[1, 2, 3], |x| async move { x * 2 }).await;
// assert_eq!(async_result, vec![2, 4, 6]);
Parallel Processing (Optional)
[]
= { = "0.1.0", = ["parallel"] }
use *;
// Parallel operations (requires parallel feature)
// let result = map_parallel(&[1, 2, 3, 4], |x| x * 2);
// assert_eq!(result, vec![2, 4, 6, 8]);
WASM Support (Optional)
[]
= { = "0.1.0", = ["wasm"] }
API Reference
Collection Operations
Iteration
map(collection, iteratee)- Transform each elementfilter(collection, predicate)- Filter elements by conditionreduce(collection, iteratee, initial)- Reduce to single valueforEach(collection, iteratee)- Execute function for each elementforEachRight(collection, iteratee)- Execute function from right to left
Query
find(collection, predicate)- Find first matching elementfindLast(collection, predicate)- Find last matching elementincludes(collection, value)- Check if value existsevery(collection, predicate)- Check if all elements matchsome(collection, predicate)- Check if any element matchescountBy(collection, iteratee)- Count elements by keypartition(collection, predicate)- Split into two groups
Transform
groupBy(collection, iteratee)- Group elements by keykeyBy(collection, iteratee)- Create object with keyssortBy(collection, iteratee)- Sort elements by keyorderBy(collection, iteratee, descending)- Sort with directioninvoke(collection, method)- Invoke method on each element
Operations
shuffle(collection)- Randomize element ordersample(collection)- Get random elementsampleSize(collection, n)- Get n random elementssize(collection)- Get collection length
Chain API
use chain;
let result = chain
.filter // [2, 4, 6, 8, 10]
.map // [6, 12, 18, 24, 30]
.take // [6, 12, 18]
.reverse // [18, 12, 6]
.collect; // Vec<i32>
Examples
See the examples/ directory for more detailed usage examples:
basic_usage.rs- Comprehensive examples of all featuresstandalone_test.rs- Simple functionality test
Performance
lodash-rs is designed for high performance:
- Zero-cost abstractions: No runtime overhead for method chaining
- Optimized algorithms: Efficient implementations of all operations
- Memory efficient: Minimal allocations and copying
- SIMD ready: Prepared for future SIMD optimizations
Compatibility
- Rust: 1.70+
- Platforms: Windows, macOS, Linux
- Architectures: x86_64, ARM64
- WASM: Full browser support
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Inspired by the original Lodash JavaScript library
- Built with modern Rust best practices
- Community feedback and contributions
Changelog
See CHANGELOG.md for a detailed list of changes.
Roadmap
- Additional collection methods
- Performance benchmarks
- SIMD optimizations
- More async operations
- Enhanced WASM bindings
- Documentation improvements