difftreelog
feat add std.remove and std.removeAt
in: master
Upstream issue: https://github.com/google/go-jsonnet/pull/689
2 files changed
crates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth254 Ok(Val::Num(arr.iter().sum::<f64>() / (arr.len() as f64)))254 Ok(Val::Num(arr.iter().sum::<f64>() / (arr.len() as f64)))255}255}256257#[builtin]258pub fn builtin_remove_at(259 arr: ArrValue,260 index: usize,261) -> Result<ArrValue> {262 let newArrLeft = arr.clone().slice(None, Some(index), None);263 let newArrRight = arr.clone().slice(Some(index + 1), None, None);264 return Ok(ArrValue::extended(265 newArrLeft.unwrap_or(ArrValue::empty()),266 newArrRight.unwrap_or(ArrValue::empty()))267 );268}269270#[builtin]271pub fn builtin_remove(arr: ArrValue, elem: Val) -> Result<ArrValue> {272 for (index, item) in arr.iter().enumerate() {273 if equals(&item?, &elem)? {274 return builtin_remove_at(arr.clone(), index) 275 }276 }277 Ok(arr)278}256279crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth83 ("contains", builtin_member::INST),83 ("contains", builtin_member::INST),84 ("count", builtin_count::INST),84 ("count", builtin_count::INST),85 ("avg", builtin_avg::INST),85 ("avg", builtin_avg::INST),86 ("removeAt", builtin_remove_at::INST),87 ("remove", builtin_remove::INST),86 // Math88 // Math87 ("abs", builtin_abs::INST),89 ("abs", builtin_abs::INST),88 ("sign", builtin_sign::INST),90 ("sign", builtin_sign::INST),