Created
April 5, 2024 18:55
-
-
Save identw/7239bcf4a995a9e37f05ca78ddd00837 to your computer and use it in GitHub Desktop.
helpers.jsonnet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
mapArrayByField(f, mixinField):: { | |
local m = super[mixinField], | |
[mixinField]: std.prune(std.map(f, m)) | |
}, | |
mapArrayWithField(fieldValues, fieldName, mixinField, f):: ( | |
local fieldValuesSet = std.set(fieldValues); | |
local inFieldValuesSet(value) = std.length(std.setInter(fieldValuesSet, std.set([value]))) > 0; | |
self.mapArrayByField(function(i) if std.objectHas(i, fieldName) && inFieldValuesSet(i[fieldName]) then f(i) else i, mixinField) | |
), | |
mergeArrayWithField(fieldValues, fieldName, mixinField, patch):: ( | |
self.mapArrayWithField(fieldValues, fieldName, mixinField, function(i) (i + patch)) | |
), | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment