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

difftreelog

perf implement std.prune in native

Yaroslav Bolyukin2024-04-07parent: #66d8cad.patch.diff
in: master

6 files changed

modifiedcmds/jrsonnet-fmt/src/main.rsdiffbeforeafterboth
--- a/cmds/jrsonnet-fmt/src/main.rs
+++ b/cmds/jrsonnet-fmt/src/main.rs
@@ -356,16 +356,16 @@
 impl Printable for Member {
 	fn print(&self, out: &mut PrintItems) {
 		match self {
-			Member::MemberBindStmt(b) => {
+			Self::MemberBindStmt(b) => {
 				p!(out, { b.obj_local() })
 			}
-			Member::MemberAssertStmt(ass) => {
+			Self::MemberAssertStmt(ass) => {
 				p!(out, { ass.assertion() })
 			}
-			Member::MemberFieldNormal(n) => {
+			Self::MemberFieldNormal(n) => {
 				p!(out, {n.field_name()} if(n.plus_token().is_some())({n.plus_token()}) {n.visibility()} str(" ") {n.expr()})
 			}
-			Member::MemberFieldMethod(m) => {
+			Self::MemberFieldMethod(m) => {
 				p!(out, {m.field_name()} {m.params_desc()} {m.visibility()} str(" ") {m.expr()})
 			}
 		}
modifiedcrates/jrsonnet-evaluator/src/manifest.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/manifest.rs
@@ -1,6 +1,6 @@
 use std::{borrow::Cow, fmt::Write};
 
-use crate::{bail, Result, State, Val};
+use crate::{bail, Result, ResultExt, State, Val};
 
 pub trait ManifestFormat {
 	fn manifest_buf(&self, val: Val, buf: &mut String) -> Result<()>;
@@ -235,7 +235,8 @@
 						}
 					}
 					buf.push_str(cur_padding);
-					manifest_json_ex_buf(&item?, buf, cur_padding, options)?;
+					manifest_json_ex_buf(&item?, buf, cur_padding, options)
+						.with_description(|| format!("elem <{i}> manifestification"))?;
 				}
 				cur_padding.truncate(old_len);
 
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -278,7 +278,7 @@
 }
 impl ObjectLike for ThisOverride {
 	fn with_this(&self, _me: ObjValue, this: ObjValue) -> ObjValue {
-		ObjValue::new(ThisOverride {
+		ObjValue::new(Self {
 			inner: self.inner.clone(),
 			this,
 		})
@@ -398,7 +398,7 @@
 		self.get_for(key, self.0.this().unwrap_or_else(|| self.clone()))
 	}
 
-	pub fn get_for(&self, key: IStr, this: ObjValue) -> Result<Option<Val>> {
+	pub fn get_for(&self, key: IStr, this: Self) -> Result<Option<Val>> {
 		self.0.get_for(key, this)
 	}
 
@@ -410,7 +410,7 @@
 		Ok(value)
 	}
 
-	fn get_raw(&self, key: IStr, this: ObjValue) -> Result<Option<Val>> {
+	fn get_raw(&self, key: IStr, this: Self) -> Result<Option<Val>> {
 		self.0.get_for_uncached(key, this)
 	}
 
@@ -422,7 +422,7 @@
 		// FIXME: Should it use `self.0.this()` in case of standalone super?
 		self.run_assertions_raw(self.clone())
 	}
-	fn run_assertions_raw(&self, this: ObjValue) -> Result<()> {
+	fn run_assertions_raw(&self, this: Self) -> Result<()> {
 		self.0.run_assertions_raw(this)
 	}
 
modifiedcrates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth
before · crates/jrsonnet-stdlib/src/arrays.rs
1#![allow(non_snake_case)]23use jrsonnet_evaluator::{4	bail,5	function::{builtin, FuncVal},6	runtime_error,7	typed::{BoundedI32, BoundedUsize, Either2, NativeFn, Typed},8	val::{equals, ArrValue, IndexableVal},9	Either, IStr, Result, Thunk, Val,10};1112pub(crate) fn eval_on_empty(on_empty: Option<Thunk<Val>>) -> Result<Val> {13	if let Some(on_empty) = on_empty {14		on_empty.evaluate()15	} else {16		bail!("expected non-empty array")17	}18}1920#[builtin]21pub fn builtin_make_array(sz: BoundedI32<0, { i32::MAX }>, func: FuncVal) -> Result<ArrValue> {22	if *sz == 0 {23		return Ok(ArrValue::empty());24	}25	if let Some(trivial) = func.evaluate_trivial() {26		let mut out = Vec::with_capacity(*sz as usize);27		for _ in 0..*sz {28			out.push(trivial.clone())29		}30		Ok(ArrValue::eager(out))31	} else {32		Ok(ArrValue::range_exclusive(0, *sz).map(func))33	}34}3536#[builtin]37pub fn builtin_repeat(what: Either![IStr, ArrValue], count: usize) -> Result<Val> {38	Ok(match what {39		Either2::A(s) => Val::string(s.repeat(count)),40		Either2::B(arr) => Val::Arr(41			ArrValue::repeated(arr, count)42				.ok_or_else(|| runtime_error!("repeated length overflow"))?,43		),44	})45}4647#[builtin]48pub fn builtin_slice(49	indexable: IndexableVal,50	index: Option<i32>,51	end: Option<i32>,52	step: Option<BoundedUsize<1, { i32::MAX as usize }>>,53) -> Result<Val> {54	indexable.slice(index, end, step).map(Val::from)55}5657#[builtin]58pub fn builtin_map(func: FuncVal, arr: IndexableVal) -> ArrValue {59	let arr = arr.to_array();60	arr.map(func)61}6263#[builtin]64pub fn builtin_flatmap(65	func: NativeFn<((Either![String, Val],), Val)>,66	arr: IndexableVal,67) -> Result<IndexableVal> {68	use std::fmt::Write;69	match arr {70		IndexableVal::Str(str) => {71			let mut out = String::new();72			for c in str.chars() {73				match func(Either2::A(c.to_string()))? {74					Val::Str(o) => write!(out, "{o}").unwrap(),75					Val::Null => continue,76					_ => bail!("in std.join all items should be strings"),77				};78			}79			Ok(IndexableVal::Str(out.into()))80		}81		IndexableVal::Arr(a) => {82			let mut out = Vec::new();83			for el in a.iter() {84				let el = el?;85				match func(Either2::B(el))? {86					Val::Arr(o) => {87						for oe in o.iter() {88							out.push(oe?);89						}90					}91					Val::Null => continue,92					_ => bail!("in std.join all items should be arrays"),93				};94			}95			Ok(IndexableVal::Arr(out.into()))96		}97	}98}99100#[builtin]101pub fn builtin_filter(func: FuncVal, arr: ArrValue) -> Result<ArrValue> {102	arr.filter(|val| bool::from_untyped(func.evaluate_simple(&(val.clone(),), false)?))103}104105#[builtin]106pub fn builtin_filter_map(107	filter_func: FuncVal,108	map_func: FuncVal,109	arr: ArrValue,110) -> Result<ArrValue> {111	Ok(builtin_filter(filter_func, arr)?.map(map_func))112}113114#[builtin]115pub fn builtin_foldl(func: FuncVal, arr: ArrValue, init: Val) -> Result<Val> {116	let mut acc = init;117	for i in arr.iter() {118		acc = func.evaluate_simple(&(acc, i?), false)?;119	}120	Ok(acc)121}122123#[builtin]124pub fn builtin_foldr(func: FuncVal, arr: ArrValue, init: Val) -> Result<Val> {125	let mut acc = init;126	for i in arr.iter().rev() {127		acc = func.evaluate_simple(&(i?, acc), false)?;128	}129	Ok(acc)130}131132#[builtin]133pub fn builtin_range(from: i32, to: i32) -> Result<ArrValue> {134	if to < from {135		return Ok(ArrValue::empty());136	}137	Ok(ArrValue::range_inclusive(from, to))138}139140#[builtin]141pub fn builtin_join(sep: IndexableVal, arr: ArrValue) -> Result<IndexableVal> {142	use std::fmt::Write;143	Ok(match sep {144		IndexableVal::Arr(joiner_items) => {145			let mut out = Vec::new();146147			let mut first = true;148			for item in arr.iter() {149				let item = item?.clone();150				if let Val::Arr(items) = item {151					if !first {152						out.reserve(joiner_items.len());153						// TODO: extend154						for item in joiner_items.iter() {155							out.push(item?);156						}157					}158					first = false;159					out.reserve(items.len());160					for item in items.iter() {161						out.push(item?);162					}163				} else if matches!(item, Val::Null) {164					continue;165				} else {166					bail!("in std.join all items should be arrays");167				}168			}169170			IndexableVal::Arr(out.into())171		}172		IndexableVal::Str(sep) => {173			let mut out = String::new();174175			let mut first = true;176			for item in arr.iter() {177				let item = item?.clone();178				if let Val::Str(item) = item {179					if !first {180						out += &sep;181					}182					first = false;183					write!(out, "{item}").unwrap()184				} else if matches!(item, Val::Null) {185					continue;186				} else {187					bail!("in std.join all items should be strings");188				}189			}190191			IndexableVal::Str(out.into())192		}193	})194}195196#[builtin]197pub fn builtin_reverse(arr: ArrValue) -> ArrValue {198	arr.reversed()199}200201#[builtin]202pub fn builtin_any(arr: ArrValue) -> Result<bool> {203	for v in arr.iter() {204		let v = bool::from_untyped(v?)?;205		if v {206			return Ok(true);207		}208	}209	Ok(false)210}211212#[builtin]213pub fn builtin_all(arr: ArrValue) -> Result<bool> {214	for v in arr.iter() {215		let v = bool::from_untyped(v?)?;216		if !v {217			return Ok(false);218		}219	}220	Ok(true)221}222223#[builtin]224pub fn builtin_member(arr: IndexableVal, x: Val) -> Result<bool> {225	match arr {226		IndexableVal::Str(str) => {227			let x: IStr = IStr::from_untyped(x)?;228			Ok(!x.is_empty() && str.contains(&*x))229		}230		IndexableVal::Arr(a) => {231			for item in a.iter() {232				let item = item?;233				if equals(&item, &x)? {234					return Ok(true);235				}236			}237			Ok(false)238		}239	}240}241242#[builtin]243pub fn builtin_contains(arr: IndexableVal, elem: Val) -> Result<bool> {244	builtin_member(arr, elem)245}246247#[builtin]248pub fn builtin_count(arr: ArrValue, x: Val) -> Result<usize> {249	let mut count = 0;250	for item in arr.iter() {251		if equals(&item?, &x)? {252			count += 1;253		}254	}255	Ok(count)256}257258#[builtin]259pub fn builtin_avg(arr: Vec<f64>, onEmpty: Option<Thunk<Val>>) -> Result<Val> {260	if arr.is_empty() {261		return eval_on_empty(onEmpty);262	}263	Ok(Val::Num(arr.iter().sum::<f64>() / (arr.len() as f64)))264}265266#[builtin]267pub fn builtin_remove_at(arr: ArrValue, at: usize) -> Result<ArrValue> {268	let newArrLeft = arr.clone().slice(None, Some(at), None);269	let newArrRight = arr.slice(Some(at + 1), None, None);270271	Ok(ArrValue::extended(272		newArrLeft.unwrap_or(ArrValue::empty()),273		newArrRight.unwrap_or(ArrValue::empty()),274	))275}276277#[builtin]278pub fn builtin_remove(arr: ArrValue, elem: Val) -> Result<ArrValue> {279	for (index, item) in arr.iter().enumerate() {280		if equals(&item?, &elem)? {281			return builtin_remove_at(arr.clone(), index);282		}283	}284	Ok(arr)285}286287#[builtin]288pub fn builtin_flatten_arrays(arrs: Vec<ArrValue>) -> ArrValue {289	pub fn flatten_inner(values: &[ArrValue]) -> ArrValue {290		if values.len() == 1 {291			return values[0].clone();292		} else if values.len() == 2 {293			return ArrValue::extended(values[0].clone(), values[1].clone());294		}295		let (a, b) = values.split_at(values.len() / 2);296		ArrValue::extended(flatten_inner(a), flatten_inner(b))297	}298	if arrs.is_empty() {299		return ArrValue::empty();300	} else if arrs.len() == 1 {301		return arrs.into_iter().next().expect("single");302	}303	flatten_inner(&arrs)304}305306#[builtin]307pub fn builtin_flatten_deep_array(value: Val) -> Result<Vec<Val>> {308	fn process(value: Val, out: &mut Vec<Val>) -> Result<()> {309		match value {310			Val::Arr(arr) => {311				for ele in arr.iter() {312					process(ele?, out)?;313				}314			}315			_ => out.push(value),316		}317		Ok(())318	}319	let mut out = Vec::new();320	process(value, &mut out)?;321	Ok(out)322}
after · crates/jrsonnet-stdlib/src/arrays.rs
1#![allow(non_snake_case)]23use jrsonnet_evaluator::{4	bail,5	function::{builtin, FuncVal},6	runtime_error,7	typed::{BoundedI32, BoundedUsize, Either2, NativeFn, Typed},8	val::{equals, ArrValue, IndexableVal},9	Either, IStr, ObjValueBuilder, Result, ResultExt, Thunk, Val,10};1112pub(crate) fn eval_on_empty(on_empty: Option<Thunk<Val>>) -> Result<Val> {13	if let Some(on_empty) = on_empty {14		on_empty.evaluate()15	} else {16		bail!("expected non-empty array")17	}18}1920#[builtin]21pub fn builtin_make_array(sz: BoundedI32<0, { i32::MAX }>, func: FuncVal) -> Result<ArrValue> {22	if *sz == 0 {23		return Ok(ArrValue::empty());24	}25	func.evaluate_trivial().map_or_else(26		|| Ok(ArrValue::range_exclusive(0, *sz).map(func)),27		|trivial| {28			let mut out = Vec::with_capacity(*sz as usize);29			for _ in 0..*sz {30				out.push(trivial.clone());31			}32			Ok(ArrValue::eager(out))33		},34	)35}3637#[builtin]38pub fn builtin_repeat(what: Either![IStr, ArrValue], count: usize) -> Result<Val> {39	Ok(match what {40		Either2::A(s) => Val::string(s.repeat(count)),41		Either2::B(arr) => Val::Arr(42			ArrValue::repeated(arr, count)43				.ok_or_else(|| runtime_error!("repeated length overflow"))?,44		),45	})46}4748#[builtin]49pub fn builtin_slice(50	indexable: IndexableVal,51	index: Option<i32>,52	end: Option<i32>,53	step: Option<BoundedUsize<1, { i32::MAX as usize }>>,54) -> Result<Val> {55	indexable.slice(index, end, step).map(Val::from)56}5758#[builtin]59pub fn builtin_map(func: FuncVal, arr: IndexableVal) -> ArrValue {60	let arr = arr.to_array();61	arr.map(func)62}6364#[builtin]65pub fn builtin_flatmap(66	func: NativeFn<((Either![String, Val],), Val)>,67	arr: IndexableVal,68) -> Result<IndexableVal> {69	use std::fmt::Write;70	match arr {71		IndexableVal::Str(str) => {72			let mut out = String::new();73			for c in str.chars() {74				match func(Either2::A(c.to_string()))? {75					Val::Str(o) => write!(out, "{o}").unwrap(),76					Val::Null => continue,77					_ => bail!("in std.join all items should be strings"),78				};79			}80			Ok(IndexableVal::Str(out.into()))81		}82		IndexableVal::Arr(a) => {83			let mut out = Vec::new();84			for el in a.iter() {85				let el = el?;86				match func(Either2::B(el))? {87					Val::Arr(o) => {88						for oe in o.iter() {89							out.push(oe?);90						}91					}92					Val::Null => continue,93					_ => bail!("in std.join all items should be arrays"),94				};95			}96			Ok(IndexableVal::Arr(out.into()))97		}98	}99}100101#[builtin]102pub fn builtin_filter(func: FuncVal, arr: ArrValue) -> Result<ArrValue> {103	arr.filter(|val| bool::from_untyped(func.evaluate_simple(&(val.clone(),), false)?))104}105106#[builtin]107pub fn builtin_filter_map(108	filter_func: FuncVal,109	map_func: FuncVal,110	arr: ArrValue,111) -> Result<ArrValue> {112	Ok(builtin_filter(filter_func, arr)?.map(map_func))113}114115#[builtin]116pub fn builtin_foldl(func: FuncVal, arr: ArrValue, init: Val) -> Result<Val> {117	let mut acc = init;118	for i in arr.iter() {119		acc = func.evaluate_simple(&(acc, i?), false)?;120	}121	Ok(acc)122}123124#[builtin]125pub fn builtin_foldr(func: FuncVal, arr: ArrValue, init: Val) -> Result<Val> {126	let mut acc = init;127	for i in arr.iter().rev() {128		acc = func.evaluate_simple(&(i?, acc), false)?;129	}130	Ok(acc)131}132133#[builtin]134pub fn builtin_range(from: i32, to: i32) -> Result<ArrValue> {135	if to < from {136		return Ok(ArrValue::empty());137	}138	Ok(ArrValue::range_inclusive(from, to))139}140141#[builtin]142pub fn builtin_join(sep: IndexableVal, arr: ArrValue) -> Result<IndexableVal> {143	use std::fmt::Write;144	Ok(match sep {145		IndexableVal::Arr(joiner_items) => {146			let mut out = Vec::new();147148			let mut first = true;149			for item in arr.iter() {150				let item = item?.clone();151				if let Val::Arr(items) = item {152					if !first {153						out.reserve(joiner_items.len());154						// TODO: extend155						for item in joiner_items.iter() {156							out.push(item?);157						}158					}159					first = false;160					out.reserve(items.len());161					for item in items.iter() {162						out.push(item?);163					}164				} else if matches!(item, Val::Null) {165					continue;166				} else {167					bail!("in std.join all items should be arrays");168				}169			}170171			IndexableVal::Arr(out.into())172		}173		IndexableVal::Str(sep) => {174			let mut out = String::new();175176			let mut first = true;177			for item in arr.iter() {178				let item = item?.clone();179				if let Val::Str(item) = item {180					if !first {181						out += &sep;182					}183					first = false;184					write!(out, "{item}").unwrap();185				} else if matches!(item, Val::Null) {186					continue;187				} else {188					bail!("in std.join all items should be strings");189				}190			}191192			IndexableVal::Str(out.into())193		}194	})195}196197#[builtin]198pub fn builtin_reverse(arr: ArrValue) -> ArrValue {199	arr.reversed()200}201202#[builtin]203pub fn builtin_any(arr: ArrValue) -> Result<bool> {204	for v in arr.iter() {205		let v = bool::from_untyped(v?)?;206		if v {207			return Ok(true);208		}209	}210	Ok(false)211}212213#[builtin]214pub fn builtin_all(arr: ArrValue) -> Result<bool> {215	for v in arr.iter() {216		let v = bool::from_untyped(v?)?;217		if !v {218			return Ok(false);219		}220	}221	Ok(true)222}223224#[builtin]225pub fn builtin_member(arr: IndexableVal, x: Val) -> Result<bool> {226	match arr {227		IndexableVal::Str(str) => {228			let x: IStr = IStr::from_untyped(x)?;229			Ok(!x.is_empty() && str.contains(&*x))230		}231		IndexableVal::Arr(a) => {232			for item in a.iter() {233				let item = item?;234				if equals(&item, &x)? {235					return Ok(true);236				}237			}238			Ok(false)239		}240	}241}242243#[builtin]244pub fn builtin_contains(arr: IndexableVal, elem: Val) -> Result<bool> {245	builtin_member(arr, elem)246}247248#[builtin]249pub fn builtin_count(arr: ArrValue, x: Val) -> Result<usize> {250	let mut count = 0;251	for item in arr.iter() {252		if equals(&item?, &x)? {253			count += 1;254		}255	}256	Ok(count)257}258259#[builtin]260pub fn builtin_avg(arr: Vec<f64>, onEmpty: Option<Thunk<Val>>) -> Result<Val> {261	if arr.is_empty() {262		return eval_on_empty(onEmpty);263	}264	Ok(Val::Num(arr.iter().sum::<f64>() / (arr.len() as f64)))265}266267#[builtin]268pub fn builtin_remove_at(arr: ArrValue, at: usize) -> Result<ArrValue> {269	let newArrLeft = arr.clone().slice(None, Some(at), None);270	let newArrRight = arr.slice(Some(at + 1), None, None);271272	Ok(ArrValue::extended(273		newArrLeft.unwrap_or(ArrValue::empty()),274		newArrRight.unwrap_or(ArrValue::empty()),275	))276}277278#[builtin]279pub fn builtin_remove(arr: ArrValue, elem: Val) -> Result<ArrValue> {280	for (index, item) in arr.iter().enumerate() {281		if equals(&item?, &elem)? {282			return builtin_remove_at(arr.clone(), index);283		}284	}285	Ok(arr)286}287288#[builtin]289pub fn builtin_flatten_arrays(arrs: Vec<ArrValue>) -> ArrValue {290	pub fn flatten_inner(values: &[ArrValue]) -> ArrValue {291		if values.len() == 1 {292			return values[0].clone();293		} else if values.len() == 2 {294			return ArrValue::extended(values[0].clone(), values[1].clone());295		}296		let (a, b) = values.split_at(values.len() / 2);297		ArrValue::extended(flatten_inner(a), flatten_inner(b))298	}299	if arrs.is_empty() {300		return ArrValue::empty();301	} else if arrs.len() == 1 {302		return arrs.into_iter().next().expect("single");303	}304	flatten_inner(&arrs)305}306307#[builtin]308pub fn builtin_flatten_deep_array(value: Val) -> Result<Vec<Val>> {309	fn process(value: Val, out: &mut Vec<Val>) -> Result<()> {310		match value {311			Val::Arr(arr) => {312				for ele in arr.iter() {313					process(ele?, out)?;314				}315			}316			_ => out.push(value),317		}318		Ok(())319	}320	let mut out = Vec::new();321	process(value, &mut out)?;322	Ok(out)323}324325#[builtin]326pub fn builtin_prune(327	a: Val,328	#[cfg(feature = "exp-preserve-order")] preserve_order: bool,329) -> Result<Val> {330	fn is_content(val: &Val) -> bool {331		match val {332			Val::Null => false,333			Val::Arr(a) => !a.is_empty(),334			Val::Obj(o) => !o.is_empty(),335			_ => true,336		}337	}338	Ok(match a {339		Val::Arr(a) => {340			let mut out = Vec::new();341			for (i, ele) in a.iter().enumerate() {342				let ele = ele343					.and_then(|v| {344						builtin_prune(345							v,346							#[cfg(feature = "exp-preserve-order")]347							preserve_order,348						)349					})350					.with_description(|| format!("elem <{i}> pruning"))?;351				if is_content(&ele) {352					out.push(ele);353				}354			}355			Val::Arr(ArrValue::eager(out))356		}357		Val::Obj(o) => {358			let mut out = ObjValueBuilder::new();359			for (name, value) in o.iter(360				#[cfg(feature = "exp-preserve-order")]361				preserve_order,362			) {363				let value = value364					.and_then(|v| {365						builtin_prune(366							v,367							#[cfg(feature = "exp-preserve-order")]368							preserve_order,369						)370					})371					.with_description(|| format!("field <{name}> pruning"))?;372				if !is_content(&value) {373					continue;374				}375				out.field(name).value(value);376			}377			Val::Obj(out.build())378		}379		_ => a,380	})381}
modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -92,6 +92,7 @@
 		("remove", builtin_remove::INST),
 		("flattenArrays", builtin_flatten_arrays::INST),
 		("flattenDeepArray", builtin_flatten_deep_array::INST),
+		("prune", builtin_prune::INST),
 		("filterMap", builtin_filter_map::INST),
 		// Math
 		("abs", builtin_abs::INST),
modifiedcrates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/std.jsonnet
+++ b/crates/jrsonnet-stdlib/src/std.jsonnet
@@ -209,25 +209,6 @@
     local arr = std.split(f, '/');
     std.join('/', std.makeArray(std.length(arr) - 1, function(i) arr[i]) + [r]),
 
-  prune(a)::
-    local isContent(b) =
-      if b == null then
-        false
-      else if std.isArray(b) then
-        std.length(b) > 0
-      else if std.isObject(b) then
-        std.length(b) > 0
-      else
-        true;
-    if std.isArray(a) then
-      [std.prune(x) for x in a if isContent($.prune(x))]
-    else if std.isObject(a) then {
-      [x]: $.prune(a[x])
-      for x in std.objectFields(a)
-      if isContent(std.prune(a[x]))
-    } else
-      a,
-
   find(value, arr)::
     if !std.isArray(arr) then
       error 'find second parameter should be an array, got ' + std.type(arr)