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

Commit

Permalink
Update code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
cxmeel committed Mar 14, 2024
1 parent 77a310c commit 5b0b65c
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 79 deletions.
10 changes: 5 additions & 5 deletions src/Array/difference.luau
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ local toSet = require("./toSet")
Returns a new array containing only values that are in the first array and not in any of the other arrays.
```lua
local array1 = { 1, 2, 3 }
local array2 = { 2, 3, 4 }
```lua
local array1 = { 1, 2, 3 }
local array2 = { 2, 3, 4 }
difference(array1, array2) -- { 1 }
```
difference(array1, array2) -- { 1 }
```
]=]
local function difference<T>(array: { T }, ...: { T }): { T }
local arraySet = toSet(array)
Expand Down
2 changes: 1 addition & 1 deletion src/Array/zip.luau
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local reduce = require("./reduce")
local array2 = { 1, 2, 3 }
zip(array1, array2)
-- { { "a", 1 }, { "b", 2 }, { "c", 3 } }
-- { { "a", 1 }, { "b", 2 }, { "c", 3 } }
```
]=]
local function zip(...: { any }): { { any } }
Expand Down
30 changes: 15 additions & 15 deletions src/Dictionary/get.luau
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
--[=[
@within Dictionary
Retrieves a value from a dictionary using a key. If the key is a dot-separated string and the `separated` parameter is `true`, the function will traverse the dictionary using the parts of the string as keys. If `separated` is a string, it'll be used as the separator. If the key is not found, the function will return `nil`.
```lua
local dictionary = {
foo = {
bar = {
baz = "qux"
}
}
}
get(dictionary, "foo.bar.baz") -- nil
get(dictionary, "foo.bar.baz", true) -- "qux"
get(dictionary, "foo$bar$baz", "$") -- "qux"
```
Retrieves a value from a dictionary using a key. If the key is a dot-separated string and the `separated` parameter is `true`, the function will traverse the dictionary using the parts of the string as keys. If `separated` is a string, it'll be used as the separator. If the key is not found, the function will return `nil`.
```lua
local dictionary = {
foo = {
bar = {
baz = "qux"
}
}
}
get(dictionary, "foo.bar.baz") -- nil
get(dictionary, "foo.bar.baz", true) -- "qux"
get(dictionary, "foo$bar$baz", "$") -- "qux"
```
]=]
local function get<K, V>(dictionary: { [K]: V }, key: K, separated: (string | boolean)?): V?
if not separated then
Expand Down
14 changes: 7 additions & 7 deletions src/Dictionary/mergeDeep.luau
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ local copyDeep = require("./copyDeep")
--[=[
@within Dictionary
Combines multiple dictionaries into a single dictionary, including nested dictionaries.
Combines multiple dictionaries into a single dictionary, including nested dictionaries.
```lua
local dictionary1 = { foo = "bar", deep = { foo = "bar" } }
local dictionary2 = { deep = { foo = "baz" } }
```lua
local dictionary1 = { foo = "bar", deep = { foo = "bar" } }
local dictionary2 = { deep = { foo = "baz" } }
mergeDeep(dictionary1, dictionary2)
-- { foo = "bar", deep = { foo = "baz" } }
```
mergeDeep(dictionary1, dictionary2)
-- { foo = "bar", deep = { foo = "baz" } }
```
]=]
local function mergeDeep<K, V>(...: { [any]: any }): { [K]: V }
local out: any = {}
Expand Down
52 changes: 22 additions & 30 deletions src/Dictionary/patchDiff.luau
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,31 @@ export type Patch<K, V> = {
--[=[
@within Dictionary
Returns an array of patches that can be applied to `dictionary` to make it equal to `other`. This is a deep comparison. The patches are similar to those used in JSON Patch.
Returns an array of patches that can be applied to `dictionary` to make it equal to `other`. This is a deep comparison. The patches are similar to those used in [JSON Patch](https://jsonpatch.com/).
```lua
local dictionary1 = {
foo = "bar",
qux = {
baz = "quux",
},
}
```lua
local dictionary1 = {
foo = "bar",
qux = {
baz = "quux",
},
}
local dictionary2 = {
foo = "bar",
qux = {
baz = "quuz",
},
baz = "quux",
}
local dictionary2 = {
foo = "bar",
qux = {
baz = "quuz",
},
baz = "quux",
}
patchDiff(dictionary1, dictionary2) --[[
{
{
op = "replace",
path = { "qux", "baz" },
value = "quuz",
},
{
op = "add",
path = { "baz" },
value = "quux",
},
}
]]
```
patchDiff(dictionary1, dictionary2) --[[
{
{ op = "replace", path = { "qux", "baz" }, value = "quuz" },
{ op = "add", path = { "baz" }, value = "quux" },
}
]]
```
]=]
local function patchDiff<K, V, T>(dictionary: { [K]: V }, other: { [K]: V }): { Patch<K, V> }
local out: { any } = {}
Expand Down
20 changes: 10 additions & 10 deletions src/Dictionary/update.luau
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ local copy = require("./copy")
--[=[
@within Dictionary
Updates a value in a dictionary with a given key. If the key does not exist, the value is added to the dictionary using the provided adder function.
Updates a value in a dictionary with a given key. If the key does not exist, the value is added to the dictionary using the provided adder function.
```lua
local dictionary = { a = 1, b = 2 }
```lua
local dictionary = { a = 1, b = 2 }
update(dictionary, "b", function(value)
return value + 1
end) -- { a = 1, b = 3 }
update(dictionary, "b", function(value)
return value + 1
end) -- { a = 1, b = 3 }
update(dictionary, "c", nil, function()
return 3
end) -- { a = 1, b = 2, c = 3 }
```
update(dictionary, "c", nil, function()
return 3
end) -- { a = 1, b = 2, c = 3 }
```
]=]
local function update<K, V, T>(
dictionary: { [K]: V },
Expand Down
14 changes: 7 additions & 7 deletions src/None.luau
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
--[=[
@within Sift
@prop None None
@within Sift
@prop None None
Luau doesn't have a built-in `undefined` type, so Sift provides a `None` value to represent the absence of a value.
Luau doesn't have a built-in `undefined` type, so Sift provides a `None` value to represent the absence of a value.
```lua
merge({ foo = "bar", baz = "qux" }, { foo = Sift.None })
-- { baz = "qux" }
```
```lua
merge({ foo = "bar", baz = "qux" }, { foo = Sift.None })
-- { baz = "qux" }
```
]=]
local None: unknown = newproxy(true)

Expand Down
8 changes: 4 additions & 4 deletions src/Set/copy.luau
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
--[=[
@within Set
Returns a shallow copy of the set.
Returns a shallow copy of the set.
```lua
copy({ a = true, b = true }) -- { a = true, b = true }
```
```lua
copy({ a = true, b = true }) -- { a = true, b = true }
```
]=]
local function copy<T>(set: { [T]: boolean }): { [T]: boolean }
local out = {}
Expand Down

0 comments on commit 5b0b65c

Please sign in to comment.