feat(tvix/eval): Support builtins.head
TL;DR: - support `builtins.head` - define `ErrorKind::IndexOutOfBounds` and canonical error code - support basic unit tests Change-Id: I859107ffb4e220cba1be8c2ac41d1913dcca37ff Reviewed-on: https://cl.tvl.fyi/c/depot/+/6544 Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com> Reviewed-by: sterni <sternenseemann@systemli.org> Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
This commit is contained in:
parent
0595870341
commit
85b3f17007
5 changed files with 27 additions and 0 deletions
|
|
@ -75,6 +75,14 @@ fn pure_builtins() -> Vec<Builtin> {
|
|||
}
|
||||
Ok(Value::Integer(args[0].to_list()?.len() as i64))
|
||||
}),
|
||||
Builtin::new("head", 1, |args, vm| {
|
||||
force!(vm, &args[0], xs, {
|
||||
match xs.to_list()?.get(0) {
|
||||
Some(x) => Ok(x.clone()),
|
||||
None => Err(ErrorKind::IndexOutOfBounds { index: 0 }),
|
||||
}
|
||||
})
|
||||
}),
|
||||
Builtin::new("isAttrs", 1, |args, _| {
|
||||
Ok(Value::Bool(matches!(args[0], Value::Attrs(_))))
|
||||
}),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue