difftreelog
feat implement std.flattenDeepArray builtin
in: master
2 files changed
crates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth303 flatten_inner(&arrs)303 flatten_inner(&arrs)304}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}305323crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth48#[cfg(feature = "exp-regex")]48#[cfg(feature = "exp-regex")]49pub use crate::regex::*;49pub use crate::regex::*;505051#[allow(clippy::too_many_lines)]51pub fn stdlib_uncached(settings: Rc<RefCell<Settings>>) -> ObjValue {52pub fn stdlib_uncached(settings: Rc<RefCell<Settings>>) -> ObjValue {52 let mut builder = ObjValueBuilder::new();53 let mut builder = ObjValueBuilder::new();5354596060 builder.with_super(eval);61 builder.with_super(eval);616263 // FIXME: Use PHF62 for (name, builtin) in [64 for (name, builtin) in [63 // Types65 // Types64 ("type", builtin_type::INST),66 ("type", builtin_type::INST),89 ("removeAt", builtin_remove_at::INST),91 ("removeAt", builtin_remove_at::INST),90 ("remove", builtin_remove::INST),92 ("remove", builtin_remove::INST),91 ("flattenArrays", builtin_flatten_arrays::INST),93 ("flattenArrays", builtin_flatten_arrays::INST),94 ("flattenDeepArray", builtin_flatten_deep_array::INST),92 ("filterMap", builtin_filter_map::INST),95 ("filterMap", builtin_filter_map::INST),93 // Math96 // Math94 ("abs", builtin_abs::INST),97 ("abs", builtin_abs::INST),196 ("__compare", builtin___compare::INST),199 ("__compare", builtin___compare::INST),197 ]200 ]198 .iter()201 .iter()199 .cloned()202 .copied()200 {203 {201 builder.method(name, builtin);204 builder.method(name, builtin);202 }205 }268 let locs = loc.0.map_source_locations(&[loc.1]);271 let locs = loc.0.map_source_locations(&[loc.1]);269 eprint!(272 eprint!(270 " {}:{}",273 " {}:{}",271 match loc.0.source_path().path() {274 loc.0.source_path().path().map_or_else(272 Some(p) => self.resolver.resolve(p),273 None => loc.0.source_path().to_string(),275 || loc.0.source_path().to_string(),276 |p| self.resolver.resolve(p)274 },277 ),275 locs[0].line278 locs[0].line276 );279 );277 }280 }416impl StateExt for State {419impl StateExt for State {417 fn with_stdlib(&self) {420 fn with_stdlib(&self) {418 let initializer = ContextInitializer::new(self.clone(), PathResolver::new_cwd_fallback());421 let initializer = ContextInitializer::new(self.clone(), PathResolver::new_cwd_fallback());419 self.settings_mut().context_initializer = tb!(initializer)422 self.settings_mut().context_initializer = tb!(initializer);420 }423 }421}424}422425