0 Star 0 Fork 15

wwwwwwwV / GraalVM

forked from Gitee 极速下载 / GraalVM 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
common-utils.libsonnet 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
{
# composable: make an object composable
#
# When composing objects with `+`, the RHS overrides the LHS when fields collide,
# unless the RHS defines fields with `+:`. This is especially an issue when
# importing nested objects from JSON, where all fields are implicitly defined
# with `:`. To solve this, `composable` essentially turns `:` fields into `+:`.
#
# See the following example:
#
# input.jsonnet
# <code>
# {
# composable:: ...,
# obj1:: {
# key1: {
# foo: "foo",
# },
# key2: "key2",
# },
# obj2:: {
# key1: {
# baz : "baz",
# },
# key3: "key3",
# },
# res1: self.obj1 + self.obj2,
# res2: self.composable(self.obj1) + self.composable(self.obj2),
# }
# </code>
#
# Output of jsonnet input.jsonnet
# <code>
# {
# "res1": {
# "key1": {
# "baz": "baz"
# },
# "key2": "key2",
# "key3": "key3"
# },
# "res2": {
# "key1": {
# "baz": "baz",
# "foo": "foo"
# },
# "key2": "key2",
# "key3": "key3"
# }
# }
# </code>
# Note the missing `res1.key1.foo`!
#
local _composable(o) =
std.foldl(function(obj, key)
obj +
if std.type(o[key]) == "object" then
{ [key] +: _composable(o[key]) }
else
{ [key] : o[key] },
std.objectFields(o),
{}
),
# exported name
composable(o) :: _composable(o),
}
1
https://gitee.com/wwwwwwwv/GraalVM.git
git@gitee.com:wwwwwwwv/GraalVM.git
wwwwwwwv
GraalVM
GraalVM
master

搜索帮助