Update deprecation warnings (#15867)

# Description
- Use #15770 to
  - improve `get --sensitive` deprecation warning
  - add deprecation warning for `filter`
- refactor `filter` to use `where` as its implementation
- replace usages of `filter` with `where` in `std`

# User-Facing Changes
- `get --sensitive` will raise a warning only once, during parsing
whereas before it was raised during runtime for each usage.
- using `filter` will raise a deprecation warning, once

# Tests + Formatting
No existing test broke or required tweaking. Additional tests covering
this case was added.
- 🟢 toolkit fmt
- 🟢 toolkit clippy
- 🟢 toolkit test
- 🟢 toolkit test stdlib

# After Submitting
N/A

---------

Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com>
This commit is contained in:
Bahex
2025-06-01 19:21:07 +03:00
committed by GitHub
parent cfbe835910
commit ad9f051d61
6 changed files with 41 additions and 102 deletions

View File

@ -18,7 +18,7 @@
export def find [
fn: closure # the closure used to perform the search
] {
filter {|e| try {do $fn $e} } | try { first }
where {|e| try {do $fn $e} } | try { first }
}
# Returns the index of the first element that matches the predicate or -1 if none
@ -87,7 +87,7 @@ export def scan [ # -> list<any>
#
# This is equivalent to
#
# $in | each $fn | filter $fn
# $in | each $fn | where $fn
@example "Get the squares of elements that can be squared" {
[2 5 "4" 7] | iter filter-map {|e| $e ** 2}
} --result [4, 25, 49]
@ -101,7 +101,7 @@ export def filter-map [
null
}
}
| filter {|e|
| where {|e|
$e != null
}
}

View File

@ -62,7 +62,7 @@ def xupdate-string-step [ step: string rest: list updater: closure ] {
let input = $in
# Get a list of elements to be updated and their indices
let to_update = ($input.content | enumerate | filter {|it|
let to_update = ($input.content | enumerate | where {|it|
let item = $it.item
$step == '*' or $item.tag == $step
})

View File

@ -333,20 +333,20 @@ export def run-tests [
commands: (get-annotated $row.name)
}
}
| filter {|x| ($x.commands|length) > 0}
| where {|x| ($x.commands|length) > 0}
| upsert commands {|module|
$module.commands
| create-test-record
}
| flatten
| filter {|x| ($x.test|length) > 0}
| filter {|x| if ($exclude_module|is-empty) {true} else {$x.name !~ $exclude_module}}
| filter {|x| if ($test|is-empty) {true} else {$x.test|any {|y| $y =~ $test}}}
| filter {|x| if ($module|is-empty) {true} else {$module == $x.name}}
| where {|x| ($x.test|length) > 0}
| where {|x| if ($exclude_module|is-empty) {true} else {$x.name !~ $exclude_module}}
| where {|x| if ($test|is-empty) {true} else {$x.test|any {|y| $y =~ $test}}}
| where {|x| if ($module|is-empty) {true} else {$module == $x.name}}
| update test {|x|
$x.test
| filter {|y| if ($test|is-empty) {true} else {$y =~ $test}}
| filter {|y| if ($exclude|is-empty) {true} else {$y !~ $exclude}}
| where {|y| if ($test|is-empty) {true} else {$y =~ $test}}
| where {|y| if ($exclude|is-empty) {true} else {$y !~ $exclude}}
}
)
if $list {