Latviaslikts/tuplerone
Tuples and value objects for JavaScript 🤷
🎯 Tuplerone — Tuple và value object trong JavaScript/TypeScript
Tuplerone cho phép so sánh giá trị kiểu danh sách bằng
===, giống như tuple trong Python.
Tuplerone là một thư viện nhỏ gọn (dưới 1KB) cung cấp cấu trúc dữ liệu tuple và value object cho JavaScript và TypeScript. Thay vì so sánh tham chiếu như mảng, Tuplerone trả về cùng một tham chiếu nếu nội dung tuple giống nhau, nhờ cấu trúc WeakMap DAG.
✨ Điểm nổi bật
- Tuple(1,2,3) === Tuple(1,2,3): so sánh giá trị thay vì tham chiếu
- Immutable: dùng Object.freeze(), không thể thay đổi thuộc tính
- Array-like & iterable: truy cập bằng chỉ số, hỗ trợ for-of và spread
- Efficient lookup: dùng WeakMap DAG để lưu trữ và tra cứu nhanh
- Tiny & zero-dependency: dưới 1KB, không phụ thuộc bên ngoài
- Type-safe: hỗ trợ TypeScript đầy đủ
- Map/WeakMap key: dùng tuple làm khóa phức hợp
💡 Vì sao đáng chú ý
Tuplerone khắc phục hạn chế của mảng trong JS: [1,2,3] !== [1,2,3]. Thay vào đó, nó dùng một WeakMap DAG để ánh xạ nội dung tuple sang một tham chiếu duy nhất — giống hệnh viễn lược trong Python. Rất hữu ích khi dùng memoization (React.memo, PureComponent), truyền danh sách làm props, hoặc dùng nhiều giá trị làm khóa Map.
#Tuple #ValueObject #Immutability #JavaScript #TypeScript #TiniX
Similar Projects
Discover other similar projects and AI models.
📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings
🔩 Like builtins, but boltons. 250+ constructs, recipes, and snippets which extend (and rely on nothing but) the Python standard library. Nothing like Michael Bolton.
《Hello 算法》:动画图解、一键运行的数据结构与算法教程。支持简中、繁中、English、日本語,提供 Python, Java, C++, C, C#, JS, Go, Swift, Rust, Ruby, Kotlin, TS, Dart 等代码实现
The AI that really does things. Any OS. Any Platform. The lobster way. 🦞
Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
For developers, who are building real-time data-driven applications, Redis is the preferred, fastest, and most feature-rich cache, data structure server, and document and vector query engine.