feat(tvix/eval): add NixList::force_elements()

This adds a function NixList::force_elements() which forces each
element of the list shallowly.  This behavior is needed for
`builtins.replaceStrings`, and probably a few other builtins as
well.

Signed-off-by: Adam Joseph <adam@westernsemico.com>
Change-Id: I3f0681acbbfe50e781b5f07b6a441647f5e6f8da
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7094
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
Adam Joseph 2022-10-26 02:02:09 -07:00
parent dc3543e0ca
commit 499a443032

View file

@ -100,6 +100,11 @@ impl NixList {
Ok(true)
}
/// force each element of the list (shallowly), making it safe to call .get().value()
pub fn force_elements(&self, vm: &mut VM) -> Result<(), ErrorKind> {
self.iter().try_for_each(|v| v.force(vm).map(|_| ()))
}
}
impl IntoIterator for NixList {