Efficient, thread-safe immutable data structures (Vector and Map) for the Crystal programming language.
Immutable is a library providing efficient, thread-safe immutable data structures for the Crystal programming language. It implements persistent collections like Vector (array-like) and Map (hash-like) where modifications return new copies while preserving the original, enabling functional programming patterns with structural sharing for performance.
Crystal developers building concurrent applications, functional programming enthusiasts, or anyone needing thread-safe collections without locking overhead.
Developers choose Immutable for its performance-optimized persistent data structures, inherent thread safety, and seamless integration with Crystal's ecosystem, offering a functional alternative to mutable collections.
Thread-safe, persistent, immutable collections for the Crystal language
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Immutability guarantees safe concurrent access without locks, making it ideal for multi-threaded Crystal applications as highlighted in the README's emphasis on thread-safe design.
Modifications return copies via structural sharing, minimizing memory overhead and performance hits compared to deep copies, with implementations like vector tries ensuring O(Log32) operations.
The transient interface allows for faster bulk modifications by temporarily using mutable operations, as demonstrated in the usage examples for handling thousands of updates efficiently.
The `.from` method easily converts nested arrays and hashes into immutable versions, integrating with existing Crystal code without manual restructuring.
Only Vector and Map are implemented, lacking other common immutable collections like sets or queues, which might require additional libraries or workarounds.
Despite being near-constant, operations have O(Log32) complexity, which can be slower than O(1) for mutable collections in performance-critical scenarios, as noted in the implementation details.
While similar to Array and Hash, the immutable API has differences (e.g., `.set` instead of assignment) that require code changes and learning effort for developers accustomed to mutable paradigms.