Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
st-Wook committed Jun 5, 2024
1 parent 30a777a commit b2b9b13
Show file tree
Hide file tree
Showing 26 changed files with 80 additions and 79 deletions.
14 changes: 7 additions & 7 deletions src/Array/difference.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
--!strict
local T = require(script.Parent.Parent.Types)

local setDifference = require(script.Parent.Parent.Set.difference)
local toArray = require(script.Parent.Parent.Set.toArray)
local toSet = require(script.Parent.toSet)
local SetDifference = require(script.Parent.Parent.Set.difference)
local ToArray = require(script.Parent.Parent.Set.toArray)
local ToSet = require(script.Parent.toSet)

--[=[
@function difference
Expand All @@ -23,20 +23,20 @@ local toSet = require(script.Parent.toSet)
```
]=]
local function difference<V>(array: T.Array<V>, ...: T.Array<V>): T.Array<V>
local arraySet = toSet(array)
local arraySet = ToSet(array)
local otherSets = {}

for _, nextArray in { ... } do
if typeof(nextArray) ~= "table" then
continue
end

table.insert(otherSets, toSet(nextArray))
table.insert(otherSets, ToSet(nextArray))
end

local differenceSet = setDifference(arraySet, unpack(otherSets))
local differenceSet = SetDifference(arraySet, unpack(otherSets))

return toArray(differenceSet)
return ToArray(differenceSet)
end

return difference
8 changes: 4 additions & 4 deletions src/Array/difference.spec.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
return function()
local difference = require(script.Parent.difference)
local Difference = require(script.Parent.difference)

it("should return the difference between two arrays", function()
local array = { "hello", "world" }
local otherArray = { "cat", "dog", "hello" }

local newArray = difference(array, otherArray)
local newArray = Difference(array, otherArray)

expect(newArray).to.be.a("table")
expect(#newArray).to.equal(1)
Expand All @@ -17,7 +17,7 @@ return function()
local array = { "hello", "world" }
local otherArray = { "cat", "dog", "hello" }

local newArray = difference(array, nil, otherArray)
local newArray = Difference(array, nil, otherArray)

expect(newArray).to.be.a("table")
expect(#newArray).to.equal(1)
Expand All @@ -30,7 +30,7 @@ return function()
local otherArray = { "cat", "dog", "hello" }
local anotherArray = { "hello", "panda" }

local newArray = difference(array, otherArray, anotherArray)
local newArray = Difference(array, otherArray, anotherArray)

expect(newArray).to.be.a("table")
expect(#newArray).to.equal(1)
Expand Down
14 changes: 7 additions & 7 deletions src/Array/differenceSymmetric.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
--!strict
local T = require(script.Parent.Parent.Types)

local setDifferenceSymmetric = require(script.Parent.Parent.Set.differenceSymmetric)
local toArray = require(script.Parent.Parent.Set.toArray)
local toSet = require(script.Parent.toSet)
local SetDifferenceSymmetric = require(script.Parent.Parent.Set.differenceSymmetric)
local ToArray = require(script.Parent.Parent.Set.toArray)
local ToSet = require(script.Parent.toSet)

--[=[
@function differenceSymmetric
Expand All @@ -23,20 +23,20 @@ local toSet = require(script.Parent.toSet)
```
]=]
local function differenceSymmetric<V>(array: T.Array<V>, ...: T.Array<V>): T.Array<V>
local arraySet = toSet(array)
local arraySet = ToSet(array)
local otherSets = {}

for _, nextArray in { ... } do
if typeof(nextArray) ~= "table" then
continue
end

table.insert(otherSets, toSet(nextArray))
table.insert(otherSets, ToSet(nextArray))
end

local differenceSet = setDifferenceSymmetric(arraySet, unpack(otherSets))
local differenceSet = SetDifferenceSymmetric(arraySet, unpack(otherSets))

return toArray(differenceSet)
return ToArray(differenceSet)
end

return differenceSymmetric
8 changes: 4 additions & 4 deletions src/Array/differenceSymmetric.spec.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
return function()
local differenceSymmetric = require(script.Parent.differenceSymmetric)
local DifferenceSymmetric = require(script.Parent.differenceSymmetric)

it("should return the symmetric difference between two arrays", function()
local array = { "hello", "world" }
local otherArray = { "cat", "dog", "hello" }

local newArray = differenceSymmetric(array, otherArray)
local newArray = DifferenceSymmetric(array, otherArray)

expect(newArray).to.be.a("table")
expect(#newArray).to.equal(3)
Expand All @@ -19,7 +19,7 @@ return function()
local array = { "hello", "world" }
local otherArray = { "cat", "dog", "hello" }

local newArray = differenceSymmetric(array, nil, otherArray)
local newArray = DifferenceSymmetric(array, nil, otherArray)

expect(newArray).to.be.a("table")
expect(#newArray).to.equal(3)
Expand All @@ -34,7 +34,7 @@ return function()
local otherArray = { "cat", "dog", "hello" }
local anotherArray = { "hello", "panda" }

local newArray = differenceSymmetric(array, otherArray, anotherArray)
local newArray = DifferenceSymmetric(array, otherArray, anotherArray)

expect(newArray).to.be.a("table")
expect(#newArray).to.equal(4)
Expand Down
1 change: 1 addition & 0 deletions src/Array/toSet.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
--!strict
local Sift = script.Parent.Parent

local _T = require(Sift.Types)

--[=[
Expand Down
4 changes: 2 additions & 2 deletions src/Dictionary/mergeDeep.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
--!strict
local Sift = script.Parent.Parent

local CopyDeep = require(script.Parent.copyDeep)
local None = require(Sift.None)
local copyDeep = require(script.Parent.copyDeep)

--[=[
@function mergeDeep
Expand Down Expand Up @@ -40,7 +40,7 @@ local function mergeDeep<T>(...: any): T
result[key] = nil
elseif type(value) == "table" then
if result[key] == nil or type(result[key]) ~= "table" then
result[key] = copyDeep(value)
result[key] = CopyDeep(value)
else
result[key] = mergeDeep(result[key], value)
end
Expand Down
4 changes: 2 additions & 2 deletions src/Dictionary/removeKey.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--!strict
local copy = require(script.Parent.copy)
local Copy = require(script.Parent.copy)

--[=[
@function removeKey
Expand All @@ -19,7 +19,7 @@ local copy = require(script.Parent.copy)
```
]=]
local function removeKey<K, V>(dictionary: { [K]: V }, key: K): { [K]: V }
local result = copy(dictionary)
local result = Copy(dictionary)

result[key] = nil

Expand Down
4 changes: 2 additions & 2 deletions src/Dictionary/removeKeys.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--!strict
local copy = require(script.Parent.copy)
local Copy = require(script.Parent.copy)

--[=[
@function removeKeys
Expand All @@ -18,7 +18,7 @@ local copy = require(script.Parent.copy)
```
]=]
local function removeKeys<K, V>(dictionary: { [K]: V }, ...: K): { [K]: V }
local result = copy(dictionary)
local result = Copy(dictionary)

for _, key in ipairs({ ... }) do
result[key] = nil
Expand Down
4 changes: 2 additions & 2 deletions src/Dictionary/set.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--!strict
local copy = require(script.Parent.copy)
local Copy = require(script.Parent.copy)

--[=[
@function set
Expand All @@ -19,7 +19,7 @@ local copy = require(script.Parent.copy)
```
]=]
local function set<K, V>(dictionary: { [K]: V }, key: K, value: V): { [K]: V }
local result = copy(dictionary)
local result = Copy(dictionary)

result[key] = value

Expand Down
4 changes: 2 additions & 2 deletions src/Dictionary/update.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--!strict
local copy = require(script.Parent.copy)
local Copy = require(script.Parent.copy)

--[=[
@function update
Expand Down Expand Up @@ -33,7 +33,7 @@ local function update<K, V, U, C>(
updater: ((value: V, key: K) -> U)?,
callback: ((key: K) -> C)?
): { [K]: V | U | C }
local result: { [K]: any } = copy(dictionary)
local result: { [K]: any } = Copy(dictionary)

if result[key] then
if updater then
Expand Down
6 changes: 3 additions & 3 deletions src/Set/add.spec.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
return function()
local add = require(script.Parent.add)
local Add = require(script.Parent.add)

it("should add values to a set", function()
local set = { hello = true }

local newSet = add(set, "world")
local newSet = Add(set, "world")

expect(newSet).to.be.a("table")

Expand All @@ -15,7 +15,7 @@ return function()
it("should not modify the original set", function()
local set = { hello = true }

add(set, "world")
Add(set, "world")

expect(set).to.be.a("table")

Expand Down
4 changes: 2 additions & 2 deletions src/Set/copy.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--!strict
local Sift = script.Parent.Parent

local copy = require(Sift.Dictionary.copy)
local Copy = require(Sift.Dictionary.copy)

--[=[
@function copy
Expand All @@ -18,4 +18,4 @@ local copy = require(Sift.Dictionary.copy)
local newSet = Copy(set) -- { hello = true }
```
]=]
return copy
return Copy
4 changes: 2 additions & 2 deletions src/Set/copy.spec.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
return function()
local copy = require(script.Parent.copy)
local Copy = require(script.Parent.copy)

it("should copy a set", function()
local set = { hello = true }

local newSet = copy(set)
local newSet = Copy(set)

expect(newSet).to.be.a("table")
expect(newSet).never.to.equal(set)
Expand Down
6 changes: 3 additions & 3 deletions src/Set/count.spec.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
return function()
local count = require(script.Parent.count)
local Count = require(script.Parent.count)

it("should count the number of values in a set", function()
local set = { hello = true, world = true }

expect(count(set)).to.equal(2)
expect(Count(set)).to.equal(2)
end)

it("should count the number of values in a set matching the predicate", function()
local set = { hello = true, world = true }

expect(count(set, function(value)
expect(Count(set, function(value)
return value == "hello"
end)).to.equal(1)
end)
Expand Down
6 changes: 3 additions & 3 deletions src/Set/delete.spec.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
return function()
local delete = require(script.Parent.delete)
local Delete = require(script.Parent.delete)

it("should delete a value from a set", function()
local set = { hello = true }

local newSet = delete(set, "hello")
local newSet = Delete(set, "hello")

expect(newSet).to.be.a("table")
expect(newSet).never.to.equal(set)
Expand All @@ -15,7 +15,7 @@ return function()
it("should not modify the original set", function()
local set = { hello = true }

delete(set, "hello")
Delete(set, "hello")

expect(set).to.be.a("table")
expect(set.hello).to.equal(true)
Expand Down
8 changes: 4 additions & 4 deletions src/Set/difference.spec.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
return function()
local difference = require(script.Parent.difference)
local Difference = require(script.Parent.difference)

it("should return the difference between two sets", function()
local set = { hello = true, world = true }
local otherSet = { panda = true, cat = true }

local newSet = difference(set, otherSet)
local newSet = Difference(set, otherSet)

expect(newSet).to.be.a("table")

Expand All @@ -19,7 +19,7 @@ return function()
local set = { hello = true, world = true }
local otherSet = { panda = true, cat = true }

local newSet = difference(set, nil, otherSet)
local newSet = Difference(set, nil, otherSet)

expect(newSet).to.be.a("table")
expect(newSet.hello).to.equal(true)
Expand All @@ -31,7 +31,7 @@ return function()
local otherSet = { panda = true, cat = true }
local anotherSet = { hello = true, panda = true }

local newSet = difference(set, otherSet, anotherSet)
local newSet = Difference(set, otherSet, anotherSet)

expect(newSet).to.be.a("table")

Expand Down
8 changes: 4 additions & 4 deletions src/Set/differenceSymmetric.spec.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
return function()
local differenceSymmetric = require(script.Parent.differenceSymmetric)
local DifferenceSymmetric = require(script.Parent.differenceSymmetric)

it("should return the symmetric difference between two sets", function()
local set = { hello = true, world = true }
local otherSet = { panda = true, cat = true }

local newSet = differenceSymmetric(set, otherSet)
local newSet = DifferenceSymmetric(set, otherSet)

expect(newSet).to.be.a("table")

Expand All @@ -19,7 +19,7 @@ return function()
local set = { hello = true, world = true }
local otherSet = { panda = true, cat = true }

local newSet = differenceSymmetric(set, nil, otherSet)
local newSet = DifferenceSymmetric(set, nil, otherSet)

expect(newSet).to.be.a("table")
expect(newSet.hello).to.equal(true)
Expand All @@ -31,7 +31,7 @@ return function()
local otherSet = { panda = true, cat = true }
local anotherSet = { hello = true, panda = true }

local newSet = differenceSymmetric(set, otherSet, anotherSet)
local newSet = DifferenceSymmetric(set, otherSet, anotherSet)

expect(newSet).to.be.a("table")

Expand Down
Loading

0 comments on commit b2b9b13

Please sign in to comment.