feat(tvix/eval): implement 'builtins.filter'
This is a little ugly because the plain Iterator::filter method can not be used (it does not support fallible primitives), so we need to resort to an `Iterator::filter_map` and deal with the wrapping in Options everywhere. This prevents use of `?` which introduces the need for some matching, but it's not *too* bad. Change-Id: Ie2c3c0c9756c4c627176f64fb4e0054e717c26d1 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6765 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
parent
1015f2f8e7
commit
f816813d41
4 changed files with 44 additions and 1 deletions
|
|
@ -0,0 +1 @@
|
|||
[ [ 1 2 3 4 5 ] [ ] [ 2 2 2 ] [ [ 1 2 ] [ 3 4 ] ] ]
|
||||
13
tvix/eval/src/tests/tvix_tests/eval-okay-builtins-filter.nix
Normal file
13
tvix/eval/src/tests/tvix_tests/eval-okay-builtins-filter.nix
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[
|
||||
(builtins.filter (_: true) [ 1 2 3 4 5 ])
|
||||
(builtins.filter (_: false) [ 1 2 3 4 5 ])
|
||||
(builtins.filter (x: x == 2) [ 1 2 1 2 1 2 ])
|
||||
|
||||
(builtins.filter (x: (builtins.length x) > 0) [
|
||||
[ ]
|
||||
[ 1 2 ]
|
||||
[ ]
|
||||
[ ]
|
||||
[ 3 4 ]
|
||||
])
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue