diff options
author | Vincent Ambo <mail@tazj.in> | 2022-10-02T16·59+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-10-03T17·39+0000 |
commit | 844d28894978ff5522cb57947edbeb8f28dad309 (patch) | |
tree | d7a3dc0a1c95a54ed16662b26b42785eb395ba3e /tvix/eval/src/builtins | |
parent | 939b2194fe6b0159191892d7bfc7ff527c1b0371 (diff) |
feat(tvix/eval): implement `builtins.all` r/5023
Change-Id: I19ec2b2194681efd73041f4aa1e5f2c893e839c2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6844 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/builtins')
-rw-r--r-- | tvix/eval/src/builtins/mod.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 94a035c2ece7..bdfa791574bb 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -61,6 +61,20 @@ fn pure_builtins() -> Vec<Builtin> { Builtin::new("abort", &[true], |args, _| { Err(ErrorKind::Abort(args[0].to_str()?.to_string())) }), + Builtin::new("all", &[true, true], |args, vm| { + for value in args[1].to_list()?.into_iter() { + let pred_result = { + vm.push(value); + vm.call_value(&args[0]) + }?; + + if !pred_result.force(vm)?.as_bool()? { + return Ok(Value::Bool(false)); + } + } + + Ok(Value::Bool(true)) + }), Builtin::new("attrNames", &[true], |args, _| { let xs = args[0].to_attrs()?; let mut output = Vec::with_capacity(xs.len()); |