git.delta.rocks / jrsonnet / refs/commits / b9668b119e46

difftreelog

feat add std.objectRemoveKey

Paweł Bęza2023-07-14parent: #3e814e5.patch.diff
in: master
Upstream issue: https://github.com/google/go-jsonnet/pull/686

2 files changed

modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -139,6 +139,7 @@
 		// Objects
 		("objectFieldsEx", builtin_object_fields_ex::INST),
 		("objectHasEx", builtin_object_has_ex::INST),
+		("objectRemoveKey", builtin_object_remove_key::INST),
 		// Manifest
 		("escapeStringJson", builtin_escape_string_json::INST),
 		("manifestJsonEx", builtin_manifest_json_ex::INST),
modifiedcrates/jrsonnet-stdlib/src/objects.rsdiffbeforeafterboth
before · crates/jrsonnet-stdlib/src/objects.rs
1use jrsonnet_evaluator::{2	function::builtin,3	val::{StrValue, Val},4	IStr, ObjValue,5};67#[builtin]8pub fn builtin_object_fields_ex(9	obj: ObjValue,10	hidden: bool,11	#[cfg(feature = "exp-preserve-order")] preserve_order: Option<bool>,12) -> Vec<Val> {13	#[cfg(feature = "exp-preserve-order")]14	let preserve_order = preserve_order.unwrap_or(false);15	let out = obj.fields_ex(16		hidden,17		#[cfg(feature = "exp-preserve-order")]18		preserve_order,19	);20	out.into_iter()21		.map(StrValue::Flat)22		.map(Val::Str)23		.collect::<Vec<_>>()24}2526#[builtin]27pub fn builtin_object_has_ex(obj: ObjValue, fname: IStr, hidden: bool) -> bool {28	obj.has_field_ex(fname, hidden)29}
after · crates/jrsonnet-stdlib/src/objects.rs
1use jrsonnet_evaluator::{2	function::builtin,3	val::{StrValue, Val},4	IStr, ObjValue, ObjValueBuilder,5};678#[builtin]9pub fn builtin_object_fields_ex(10	obj: ObjValue,11	hidden: bool,12	#[cfg(feature = "exp-preserve-order")] preserve_order: Option<bool>,13) -> Vec<Val> {14	#[cfg(feature = "exp-preserve-order")]15	let preserve_order = preserve_order.unwrap_or(false);16	let out = obj.fields_ex(17		hidden,18		#[cfg(feature = "exp-preserve-order")]19		preserve_order,20	);21	out.into_iter()22		.map(StrValue::Flat)23		.map(Val::Str)24		.collect::<Vec<_>>()25}2627#[builtin]28pub fn builtin_object_has_ex(obj: ObjValue, fname: IStr, hidden: bool) -> bool {29	obj.has_field_ex(fname, hidden)30}3132#[builtin]33pub fn builtin_object_remove_key(obj: ObjValue, key: IStr) -> ObjValue {34	let mut new_obj = ObjValueBuilder::with_capacity(obj.len() - 1);35	for (k, v) in obj.iter() {36		if k == key {37			continue38		}39		new_obj.member(k).value_unchecked(v.unwrap())40	}4142	new_obj.build()43}