Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow function negation -f to work like !f #55920

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,29 @@ julia> filter(!isletter, str)
!(f::Function) = (!) f
!(f::ComposedFunction{typeof(!)}) = f.inner #allows !!f === f

"""
-f::Function
When the argument of `-` is a function, it returns `(-) ∘ f`.
See also [`!`](@ref) for boolean negation, and [`∘`](@ref).
# Examples
```jldoctest
julia> map(-abs2, Tuple(-2:2))
(-4, -1, 0, -1, -4)
julia> sum(-log10, [1 0.1; 0.01 0.001]; dims=1)
1×2 Matrix{Float64}:
2.0 4.0
```
!!! compat "Julia 1.12"
This method requires at least Julia 1.12.
"""
-(f::Function) = (-) f
-(f::ComposedFunction{typeof(-)}) = f.inner #allows -(-f) === f
Copy link
Contributor

Choose a reason for hiding this comment

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

This method seems fit for an independent PR. I think it'd be merged easier than the feature addition.


"""
Fix{N}(f, x)
Expand Down
Loading