forked from Roblox/graphql-lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapValueOrdered.lua
More file actions
30 lines (28 loc) · 888 Bytes
/
mapValueOrdered.lua
File metadata and controls
30 lines (28 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
--[[
* Copyright (c) GraphQL Contributors
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
]]
-- ROBLOX upstream: https://github.com/graphql/graphql-js/blob/00d4efea7f5b44088356798afff0317880605f4d/src/jsutils/mapValue.js
--[[
* Creates an object map with the same keys as `map` and values generated by
* running each value of `map` thru `fn`.
]]
local LuauPolyfill = require("@pkg/@jsdotlua/luau-polyfill")
local Map = LuauPolyfill.Map
type Map<T, V> = LuauPolyfill.Map<T, V>
local function mapValueOrdered<T, V>(
map: Map<string, T>,
fn: (value: T, key: string) -> V
): Map<string, V>
local result = Map.new() :: Map<string, V>
for _, entry in map do
local key, value = entry[1], entry[2]
result:set(key, fn(value, key))
end
return result
end
return {
mapValueOrdered = mapValueOrdered,
}