feat(tvix/eval): implement builtins.concatLists
Concatenates (but not flattens) a list of lists. Change-Id: I692e0b3e7b5a5ff93d5768d3a27849b432ec5747 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6843 Autosubmit: tazjin <tazjin@tvl.su> Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
This commit is contained in:
		
							parent
							
								
									3c9520a4e5
								
							
						
					
					
						commit
						939b2194fe
					
				
					 3 changed files with 21 additions and 0 deletions
				
			
		|  | @ -116,6 +116,20 @@ fn pure_builtins() -> Vec<Builtin> { | |||
|                 std::cmp::Ordering::Greater => Ok(Value::Integer(1)), | ||||
|             } | ||||
|         }), | ||||
|         Builtin::new("concatLists", &[true], |args, vm| { | ||||
|             let list = args[0].to_list()?; | ||||
|             let lists = list | ||||
|                 .into_iter() | ||||
|                 .map(|elem| { | ||||
|                     let value = elem.force(vm)?; | ||||
|                     value.to_list() | ||||
|                 }) | ||||
|                 .collect::<Result<Vec<NixList>, ErrorKind>>()?; | ||||
| 
 | ||||
|             Ok(Value::List(NixList::from( | ||||
|                 lists.into_iter().flatten().collect::<Vec<Value>>(), | ||||
|             ))) | ||||
|         }), | ||||
|         Builtin::new( | ||||
|             "div", | ||||
|             &[false, false], | ||||
|  |  | |||
|  | @ -0,0 +1 @@ | |||
| [ [ ] [ 1 2 3 4 5 6 ] [ [ 1 ] [ 2 ] [ 3 ] ] [ 1 2 3 4 5 6 ] ] | ||||
|  | @ -0,0 +1,6 @@ | |||
| [ | ||||
|   (builtins.concatLists [ ]) | ||||
|   (builtins.concatLists [ [ 1 2 ] [ 3 4 ] [ 5 6 ] ]) | ||||
|   (builtins.concatLists [ [ [ 1 ] [ 2 ] ] [ [ 3 ] ] [ ] ]) | ||||
|   (builtins.concatLists [ [ 1 2 ] [ ] [ 3 4 ] [ ] [ 5 6 ] ]) | ||||
| ] | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue