Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,33 @@ function filter!(f, a::AbstractVector)
return a
end

"""
filter(f)

Create a function that filters its arguments with function `f` using [`filter`](@ref), i.e.
a function equivalent to `x -> filter(f, x)`.

The returned function is of type `Base.Fix1{typeof(filter)}`, which can be
used to implement specialized methods.

# Examples
```jldoctest
julia> (1, 2, Inf, 4, NaN, 6) |> filter(isfinite)
(1, 2, 4, 6)

julia> map(filter(iseven), [1:3, 2:4, 3:5])
3-element Vector{Vector{Int64}}:
[2]
[2, 4]
[4]
```
!!! compat "Julia 1.8"
This method requires at least Julia 1.8.
Comment on lines +2656 to +2657
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be 1.9 right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
!!! compat "Julia 1.8"
This method requires at least Julia 1.8.
!!! compat "Julia 1.9"
This method requires at least Julia 1.9.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was hoping that GitHub provides a way to make a new PR from a comment like this. Alas...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created the old fashioned way: #47045.

"""
function filter(f)
Fix1(filter, f)
end

"""
keepat!(a::Vector, inds)
keepat!(a::BitVector, inds)
Expand Down
3 changes: 3 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,9 @@ end
@test isempty(eoa)
end

@testset "filter curried #41173" begin
@test -5:5 |> filter(iseven) == -4:2:4
end
@testset "logical keepat!" begin
# Vector
a = Vector(1:10)
Expand Down