feat(tvix/eval): Support builtins.hasAttr
See unit tests for examples :) Change-Id: Ieec51d780a7762cc455ca03a9dc1648a0711924a Reviewed-on: https://cl.tvl.fyi/c/depot/+/6553 Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com> Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
This commit is contained in:
parent
5b165e7318
commit
059f4b964f
3 changed files with 16 additions and 0 deletions
|
@ -134,6 +134,12 @@ fn pure_builtins() -> Vec<Builtin> {
|
|||
Builtin::new("length", &[true], |args, _| {
|
||||
Ok(Value::Integer(args[0].to_list()?.len() as i64))
|
||||
}),
|
||||
Builtin::new("hasAttr", &[true, true], |args, _| {
|
||||
let k = args[0].to_str()?;
|
||||
let xs = args[1].to_attrs()?;
|
||||
|
||||
Ok(Value::Bool(xs.contains(k.as_str())))
|
||||
}),
|
||||
Builtin::new("head", &[true], |args, _| match args[0].to_list()?.get(0) {
|
||||
Some(x) => Ok(x.clone()),
|
||||
None => Err(ErrorKind::IndexOutOfBounds { index: 0 }),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue