Skip to content

Commit

Permalink
Release 0.2.1: Map.Clone1D, Map.CloneDeep, Map.Equals1D, Set _call
Browse files Browse the repository at this point in the history
  • Loading branch information
tpc9000 committed Sep 15, 2022
1 parent f5ddf05 commit fb6692f
Show file tree
Hide file tree
Showing 10 changed files with 442 additions and 17 deletions.
7 changes: 7 additions & 0 deletions aftman.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file lists tools managed by Aftman, a cross-platform toolchain manager.
# For more information, see https://github.com/LPGhatguy/aftman

# To add a new tool, add an entry to this table.
[tools]
rojo = "rojo-rbx/[email protected]"
# rojo = "rojo-rbx/[email protected]"
277 changes: 263 additions & 14 deletions build.rbxlx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
</Vector3>
<string name="Name">Workspace</string>
<bool name="NeedsPivotMigration">false</bool>
<token name="PhysicsInertiaAndVolumeFix">0</token>
<token name="PhysicsSteppingMethod">0</token>
<Ref name="PrimaryPart">null</Ref>
<token name="ReplicateInstanceDestroySetting">0</token>
Expand All @@ -53,12 +52,14 @@
<int64 name="SourceAssetId">-1</int64>
<token name="StreamOutBehavior">0</token>
<bool name="StreamingEnabled">false</bool>
<token name="StreamingIntegrityMode">0</token>
<int name="StreamingMinRadius">64</int>
<token name="StreamingPauseMode">0</token>
<int name="StreamingTargetRadius">1024</int>
<BinaryString name="Tags"></BinaryString>
<bool name="TerrainWeldsFixed">true</bool>
<bool name="TouchesUseCollisionGroups">false</bool>
<token name="UnionsScaleNonuniformly">0</token>
<UniqueId name="UniqueId">04106338adabb71e02c7f9e70001e0ea</UniqueId>
<OptionalCoordinateFrame name="WorldPivotData">
<CFrame>
Expand All @@ -81,18 +82,18 @@
<Properties>
<BinaryString name="AttributesSerialize"></BinaryString>
<CoordinateFrame name="CFrame">
<X>10.7506285</X>
<Y>15.2252979</Y>
<Z>-19.7745552</Z>
<R00>-0.926407576</R00>
<R01>0.0932141542</R01>
<R02>-0.364801496</R02>
<X>10.5231457</X>
<Y>15.2536755</Y>
<Z>-19.6557045</Z>
<R00>-0.868420303</R00>
<R01>0.129785329</R01>
<R02>-0.478541583</R02>
<R10>-0</R10>
<R11>0.968870997</R11>
<R12>0.247566104</R12>
<R20>0.376522273</R20>
<R21>0.22934711</R21>
<R22>-0.897569418</R22>
<R11>0.965134621</R11>
<R12>0.261754274</R12>
<R20>0.495828897</R20>
<R21>0.227312729</R21>
<R22>-0.838142395</R22>
</CoordinateFrame>
<Ref name="CameraSubject">null</Ref>
<token name="CameraType">0</token>
Expand Down Expand Up @@ -151,6 +152,7 @@
<bool name="CanQuery">true</bool>
<bool name="CanTouch">true</bool>
<bool name="CastShadow">true</bool>
<string name="CollisionGroup">Default</string>
<int name="CollisionGroupId">0</int>
<Color3uint8 name="Color3uint8">4288914085</Color3uint8>
<PhysicalProperties name="CustomPhysicalProperties">
Expand Down Expand Up @@ -234,6 +236,7 @@ gcLgc4RKxr21zq2UlJSM]]></BinaryString>
<bool name="Disabled">false</bool>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">Script</string>
<token name="RunContext">0</token>
<string name="ScriptGuid">{24B6E9CB-84A6-48A2-BE30-D1B04DB0ECEA}</string>
<ProtectedString name="Source"></ProtectedString>
<int64 name="SourceAssetId">-1</int64>
Expand All @@ -254,6 +257,16 @@ gcLgc4RKxr21zq2UlJSM]]></BinaryString>
<int64 name="SourceAssetId">-1</int64>
<BinaryString name="Tags"></BinaryString>
<UniqueId name="UniqueId">04106338adabb71e02c7f9e70001fac9</UniqueId>
<token name="VolumetricAudio">1</token>
</Properties>
</Item>
<Item class="VideoCaptureService" referent="RBX3F5B01EB2CA14930B8A970E18DD8470B">
<Properties>
<BinaryString name="AttributesSerialize"></BinaryString>
<string name="Name">Instance</string>
<int64 name="SourceAssetId">-1</int64>
<BinaryString name="Tags"></BinaryString>
<UniqueId name="UniqueId">7eba3597f692b7fc03344ea100021dc4</UniqueId>
</Properties>
</Item>
<Item class="NonReplicatedCSGDictionaryService" referent="RBX0A282A97F72642FD942DB1B209FF1FAC">
Expand Down Expand Up @@ -1998,22 +2011,257 @@ end]]></ProtectedString>
<UniqueId name="UniqueId">04106338adabb71e02c7f9e70001fbac</UniqueId>
</Properties>
</Item>
<Item class="ModuleScript" referent="RBXE786779EC052486197849DC1056D98C0">
<Properties>
<BinaryString name="AttributesSerialize"></BinaryString>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">Equals1D.spec</string>
<string name="ScriptGuid">{9F9D1B0A-4A9D-4708-8B0F-522045576DE0}</string>
<ProtectedString name="Source"><![CDATA[return function()
local Equals1D = require(script.Parent.Equals1D)

describe("Map/Equals1D", function()
it("it should return true for two empty tables", function()
expect(Equals1D({}, {})).to.equal(true)
end)

it("should return false for one item in X and none in Y", function()
expect(Equals1D({a = 1}, {})).to.equal(false)
end)

it("should return false for one item in Y and none in X", function()
expect(Equals1D({}, {a = 1})).to.equal(false)
end)

it("should return false for one item in X and one item in Y with different keys", function()
expect(Equals1D({a = 1}, {b = 1})).to.equal(false)
end)

it("should return false for one item in X and one item in Y with different values", function()
expect(Equals1D({a = 1}, {a = 2})).to.equal(false)
end)

it("should return true for one item in X and one item in Y with the same key and value", function()
expect(Equals1D({a = 1}, {a = 1})).to.equal(true)
end)

it("should return true for two items in X and two items in Y with the same keys and values", function()
expect(Equals1D({a = 1, b = 2}, {a = 1, b = 2})).to.equal(true)
end)
end)
end]]></ProtectedString>
<int64 name="SourceAssetId">-1</int64>
<BinaryString name="Tags"></BinaryString>
<UniqueId name="UniqueId">7eba3597f692b7fc03344ea10002f818</UniqueId>
</Properties>
</Item>
<Item class="ModuleScript" referent="RBXB4DA3676A01B4624A3DCE8B89F4D0B84">
<Properties>
<BinaryString name="AttributesSerialize"></BinaryString>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">CloneDeep.spec</string>
<string name="ScriptGuid">{A91250F2-6B77-4DBA-BB29-1E8ECCDC515B}</string>
<ProtectedString name="Source"><![CDATA[return function()
local CloneDeep = require(script.Parent.CloneDeep)
local Equals1D = require(script.Parent.Equals1D)

describe("Map/CloneDeep", function()
it("it should copy a blank array into a new blank array", function()
local Target = {}
local Copied = CloneDeep(Target)

expect(next(Copied)).never.to.be.ok()
expect(Target).never.to.equal(Copied)
end)

it("should copy a single element", function()
local Target = {X = 1}
local Copied = CloneDeep(Target)

expect(Target).never.to.equal(Copied)
expect(Equals1D(Target, Copied)).to.equal(true)
end)

it("should copy a multiple elements", function()
local Target = {X = 1, Y = 2, Z = 3}
local Copied = CloneDeep(Target)

expect(Target).never.to.equal(Copied)
expect(Equals1D(Target, Copied)).to.equal(true)
end)

it("should copy a nested table", function()
local Target = {X = 1, Y = {Z = 2, W = {P = "Test"}}}
local Copied = CloneDeep(Target)

expect(Target).never.to.equal(Copied)
expect(Copied.X).to.equal(1)
expect(Copied.Y).to.be.ok()
expect(Copied.Y).never.to.equal(Target.Y)
expect(Copied.Y.Z).to.equal(2)
expect(Copied.Y.W).to.be.ok()
expect(Copied.Y.W).never.to.equal(Target.Y.W)
expect(Copied.Y.W.P).to.equal("Test")
end)
end)
end]]></ProtectedString>
<int64 name="SourceAssetId">-1</int64>
<BinaryString name="Tags"></BinaryString>
<UniqueId name="UniqueId">7eba3597f692b7fc03344ea10002f81a</UniqueId>
</Properties>
</Item>
<Item class="ModuleScript" referent="RBX28FB129A4A1644E095804B4D329783F4">
<Properties>
<BinaryString name="AttributesSerialize"></BinaryString>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">Clone1D</string>
<string name="ScriptGuid">{B5EF7DFF-A316-43DB-B9BC-1FCEF5890043}</string>
<ProtectedString name="Source"><![CDATA[--- Copies a data structure on the top level
local function Clone1D<K, V>(Structure: {[K]: V}): {[K]: V}
local Result = {}

for Key, Value in Structure do
Result[Key] = Value
end

return Result
end

return Clone1D]]></ProtectedString>
<int64 name="SourceAssetId">-1</int64>
<BinaryString name="Tags"></BinaryString>
<UniqueId name="UniqueId">7eba3597f692b7fc03344ea10002f81c</UniqueId>
</Properties>
</Item>
<Item class="ModuleScript" referent="RBXF482A1993EF64D499CCE7424C4C1E583">
<Properties>
<BinaryString name="AttributesSerialize"></BinaryString>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">Equals1D</string>
<string name="ScriptGuid">{71799559-BB2C-470A-BB7A-F6BB12877926}</string>
<ProtectedString name="Source"><![CDATA[--- Checks if two structures are equal on their top level
local function Equals1D(X: any, Y: any): boolean
for Key, Value in X do
if (Value ~= Y[Key]) then
return false
end
end

for Key, Value in Y do
if (Value ~= X[Key]) then
return false
end
end

return true
end

return Equals1D]]></ProtectedString>
<int64 name="SourceAssetId">-1</int64>
<BinaryString name="Tags"></BinaryString>
<UniqueId name="UniqueId">7eba3597f692b7fc03344ea10002f81e</UniqueId>
</Properties>
</Item>
<Item class="ModuleScript" referent="RBX773ADDD8B66E4EA9ACB81D91000D75C0">
<Properties>
<BinaryString name="AttributesSerialize"></BinaryString>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">CloneDeep</string>
<string name="ScriptGuid">{812BF44F-D067-405B-A35F-8F0A200DEDFE}</string>
<ProtectedString name="Source"><![CDATA[local TYPE_TABLE = "table"

--- Copies a data structure on all depth levels
local function CopyDeep<K, V>(Structure: {[K]: V}): {[K]: V}
local Result = {}

for Key, Value in Structure do
Result[Key] = if (typeof(Value) == TYPE_TABLE) then CopyDeep(Value) else Value
end

return Result
end

return CopyDeep]]></ProtectedString>
<int64 name="SourceAssetId">-1</int64>
<BinaryString name="Tags"></BinaryString>
<UniqueId name="UniqueId">7eba3597f692b7fc03344ea10002f820</UniqueId>
</Properties>
</Item>
<Item class="ModuleScript" referent="RBXE65865D1B43B497BA67073AA2A7729C3">
<Properties>
<BinaryString name="AttributesSerialize"></BinaryString>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">Clone1D.spec</string>
<string name="ScriptGuid">{96A0E652-9766-4E36-9054-F9F481544FFB}</string>
<ProtectedString name="Source"><![CDATA[return function()
local Clone1D = require(script.Parent.Clone1D)
local Equals1D = require(script.Parent.Equals1D)

describe("Map/Clone1D", function()
it("it should copy a blank array into a new blank array", function()
local Target = {}
local Copied = Clone1D(Target)

expect(next(Copied)).never.to.be.ok()
expect(Target).never.to.equal(Copied)
end)

it("should copy a single element", function()
local Target = {X = 1}
local Copied = Clone1D(Target)

expect(Target).never.to.equal(Copied)
expect(Equals1D(Target, Copied)).to.equal(true)
end)

it("should copy a multiple elements", function()
local Target = {X = 1, Y = 2, Z = 3}
local Copied = Clone1D(Target)

expect(Target).never.to.equal(Copied)
expect(Equals1D(Target, Copied)).to.equal(true)
end)

it("should copy a nested table", function()
local Target = {X = 1, Y = {Z = 2, W = {P = "Test"}}}
local Copied = Clone1D(Target)

expect(Target).never.to.equal(Copied)
expect(Copied.X).to.equal(1)
expect(Copied.Y).to.be.ok()
expect(Copied.Y).to.equal(Target.Y)
end)
end)
end]]></ProtectedString>
<int64 name="SourceAssetId">-1</int64>
<BinaryString name="Tags"></BinaryString>
<UniqueId name="UniqueId">7eba3597f692b7fc03344ea10002fcfa</UniqueId>
</Properties>
</Item>
</Item>
<Item class="ModuleScript" referent="45">
<Properties>
<BinaryString name="AttributesSerialize"></BinaryString>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">Set</string>
<string name="ScriptGuid">{F47ECC11-C03E-44D2-BEA0-5606AD28BE9F}</string>
<ProtectedString name="Source"><![CDATA[return {
<ProtectedString name="Source"><![CDATA[local Result = {
FromValues = require(script:WaitForChild("FromValues"));
FromKeys = require(script:WaitForChild("FromKeys"));

Intersection = require(script:WaitForChild("Intersection"));
Negation = require(script:WaitForChild("Negation"));
Union = require(script:WaitForChild("Union"));
Outer = require(script:WaitForChild("Outer"));
};]]></ProtectedString>
};

setmetatable(Result, { -- Allows for Set({"X", "Y", "Z"})
__call = function(_, ...)
return Result.FromValues(...)
end;
})

return Result]]></ProtectedString>
<int64 name="SourceAssetId">-1</int64>
<BinaryString name="Tags"></BinaryString>
<UniqueId name="UniqueId">04106338adabb71e02c7f9e70001fbad</UniqueId>
Expand Down Expand Up @@ -2669,6 +2917,7 @@ return true]]></ProtectedString>
<token name="DevComputerMovementMode">0</token>
<token name="DevTouchCameraMovementMode">0</token>
<token name="DevTouchMovementMode">0</token>
<token name="EnableDynamicHeads">0</token>
<bool name="EnableMouseLockOption">true</bool>
<int64 name="GameSettingsAssetIDFace">0</int64>
<int64 name="GameSettingsAssetIDHead">0</int64>
Expand Down
12 changes: 12 additions & 0 deletions src/Map/Clone1D.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- Copies a data structure on the top level
local function Clone1D<K, V>(Structure: {[K]: V}): {[K]: V}
local Result = {}

for Key, Value in Structure do
Result[Key] = Value
end

return Result
end

return Clone1D
Loading

0 comments on commit fb6692f

Please sign in to comment.