@quenty/tuple 1.0.1-canary.478.34e8ede.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,9 +3,36 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## 1.0.1-canary.478.34e8ede.0 (2024-08-27)
6
+ # 1.1.0 (2024-09-12)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Fix tuple string conversion ([9b907d5](https://github.com/Quenty/NevermoreEngine/commit/9b907d5d068e2b73fb9de6a8aef89504b30ccb22))
7
12
 
8
13
 
9
14
  ### Features
10
15
 
11
16
  * Add tuple package and fix tie signal ([134f90c](https://github.com/Quenty/NevermoreEngine/commit/134f90c03b265b9d2232198475ca27f4d5e87071))
17
+ * Add TupleLookup ([4de1c5f](https://github.com/Quenty/NevermoreEngine/commit/4de1c5fcd226fdcb5f23f26cd0b3ec31005a5330))
18
+
19
+
20
+
21
+
22
+
23
+ # v1.1.0 (Thu Sep 12 2024)
24
+
25
+ #### 🚀 Enhancement
26
+
27
+ - feat: Support hot-reloading from a hoarcekat story [#478](https://github.com/Quenty/NevermoreEngine/pull/478) ([@Quenty](https://github.com/Quenty))
28
+ - feat: Add TupleLookup ([@Quenty](https://github.com/Quenty))
29
+ - feat: Add tuple package and fix tie signal ([@Quenty](https://github.com/Quenty))
30
+
31
+ #### 🐛 Bug Fix
32
+
33
+ - style: Fix linting docs ([@Quenty](https://github.com/Quenty))
34
+ - fix: Fix tuple string conversion ([@Quenty](https://github.com/Quenty))
35
+
36
+ #### Authors: 1
37
+
38
+ - James Onnen ([@Quenty](https://github.com/Quenty))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/tuple",
3
- "version": "1.0.1-canary.478.34e8ede.0",
3
+ "version": "1.1.0",
4
4
  "description": "Tuple utility package",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -25,10 +25,11 @@
25
25
  "Quenty"
26
26
  ],
27
27
  "dependencies": {
28
- "@quenty/loader": "10.3.1-canary.478.34e8ede.0"
28
+ "@quenty/loader": "^10.4.0",
29
+ "@quenty/lrucache": "^1.2.0"
29
30
  },
30
31
  "publishConfig": {
31
32
  "access": "public"
32
33
  },
33
- "gitHead": "34e8edee97fa93a0a5bd84442b85826082444f2a"
34
+ "gitHead": "fb172906f3ee725269ec1e5f4daf9dca227e729d"
34
35
  }
@@ -8,10 +8,22 @@ local Tuple = {}
8
8
  Tuple.ClassName = "Tuple"
9
9
  Tuple.__index = Tuple
10
10
 
11
+ --[=[
12
+ Constructs a new tuple
13
+
14
+ @param ... any
15
+ @return Tuple<T>
16
+ ]=]
11
17
  function Tuple.new(...)
12
18
  return setmetatable(table.pack(...), Tuple)
13
19
  end
14
20
 
21
+ --[=[
22
+ Returns true of the value is a tuple
23
+
24
+ @param value any
25
+ @return boolean
26
+ ]=]
15
27
  function Tuple.isTuple(value)
16
28
  return getmetatable(value) == Tuple
17
29
  end
@@ -34,14 +46,30 @@ function Tuple:ToArray()
34
46
  return { self:Unpack() }
35
47
  end
36
48
 
49
+ --[=[
50
+ Converts the tuple to a string for easy debugging
51
+ ]=]
37
52
  function Tuple:__tostring()
38
- return table.concat(self, ", ")
53
+ local converted = {}
54
+ for i=1, self.n do
55
+ converted[i] = tostring(self[i])
56
+ end
57
+ return table.concat(converted, ", ")
39
58
  end
40
59
 
60
+ --[=[
61
+ Returns the length of the tuple
62
+
63
+ @return number
64
+ ]=]
41
65
  function Tuple:__len()
42
66
  return self.n
43
67
  end
44
68
 
69
+ --[=[
70
+ Compares the tuple to another tuple
71
+ @param other Tuple
72
+ ]=]
45
73
  function Tuple:__eq(other)
46
74
  if not Tuple.isTuple(other) then
47
75
  return false
@@ -60,6 +88,10 @@ function Tuple:__eq(other)
60
88
  return true
61
89
  end
62
90
 
91
+ --[=[
92
+ Combines the tuple
93
+ @param other Tuple
94
+ ]=]
63
95
  function Tuple:__add(other)
64
96
  assert(Tuple.isTuple(other), "Can only add tuples")
65
97
 
@@ -72,6 +104,11 @@ function Tuple:__add(other)
72
104
  return result
73
105
  end
74
106
 
107
+ --[=[
108
+ Unpacks the tuple
109
+
110
+ @return ...
111
+ ]=]
75
112
  function Tuple:__call()
76
113
  return table.unpack(self, 1, self.n)
77
114
  end
@@ -0,0 +1,43 @@
1
+ --[=[
2
+ Helps look up tuples that can be used as keys
3
+
4
+ @class TupleLookup
5
+ ]=]
6
+
7
+ local require = require(script.Parent.loader).load(script)
8
+
9
+ local Tuple = require("Tuple")
10
+
11
+ local TupleLookup = {}
12
+ TupleLookup.ClassName = "TupleLookup"
13
+ TupleLookup.__index = TupleLookup
14
+
15
+ function TupleLookup.new()
16
+ local self = setmetatable({}, TupleLookup)
17
+
18
+ self._tuples = setmetatable({}, { __mode = "k"})
19
+
20
+ return self
21
+ end
22
+
23
+ --[=[
24
+ Gets a shared tuple with a weak table
25
+
26
+ @param ... any
27
+ @return Tuple<T>
28
+ ]=]
29
+ function TupleLookup:ToTuple(...)
30
+ local created = Tuple.new(...)
31
+
32
+ for item, _ in pairs(self._tuples) do
33
+ if item == created then
34
+ return item
35
+ end
36
+ end
37
+
38
+ self._tuples[created] = true
39
+
40
+ return created
41
+ end
42
+
43
+ return TupleLookup