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

Add Fix{N} for fixing a single positional argument at any position #829

Merged
merged 15 commits into from
Aug 7, 2024

Conversation

MilesCranmer
Copy link
Member

@MilesCranmer MilesCranmer commented Aug 3, 2024

Adds JuliaLang/julia#54653.

Fixes #828.

julia> using Compat: Fix

julia> map(Fix{3}(muladd, 1.0), 1:3, 4:6)
3-element Vector{Float64}:
  5.0
 11.0
 19.0

Multiple dispatch: This is a bit of an edge case, and presumably many functions in Compat are like this, but since Fix1 is broadly used:

Note that even with this PR, Compat.Fix{1} is not the same as Base.Fix1 on Julia versions earlier than 1.12.0-DEV.966. Therefore, if you wish to use this as a way to dispatch on Fix{N} for libraries compatible with Julia earlier than v1.12, you should declare a function both for Compat.Fix{1} as well as Base.Fix1. You can do this with a

@static if !isdefined(Base, :Fix)
    #= Declare additional methods for Compat.Fix =#
end

Copy link
Contributor

@mcabbott mcabbott left a comment

Choose a reason for hiding this comment

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

LGTM, but I don't have merge rights.

@MilesCranmer
Copy link
Member Author

@martinholters would you be willing to take a look

Copy link
Member

@martinholters martinholters left a comment

Choose a reason for hiding this comment

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

Note that even with this PR, Compat.Fix{1} is not the same as Base.Fix1 on Julia versions earlier than 1.12.0-DEV.966. Therefore, if you wish to use this as a way to dispatch on Fix{N} for libraries compatible with Julia earlier than v1.12, you should declare a function both for Compat.Fix{1} as well as Base.Fix1.

Should this be documented somewhere more findable than the PR description?

Apart from that LGTM.

src/Compat.jl Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
MilesCranmer and others added 2 commits August 6, 2024 04:29
Co-authored-by: Martin Holters <[email protected]>
Co-authored-by: Martin Holters <[email protected]>
@MilesCranmer
Copy link
Member Author

Should this be documented somewhere more findable than the PR description?

I’ll add it to the docs for the function

@MilesCranmer
Copy link
Member Author

Done.

Copy link
Member

@martinholters martinholters left a comment

Choose a reason for hiding this comment

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

LGTM. Barring objections, I'll merge this and #830 tomorrow and tag a new version.

@MilesCranmer
Copy link
Member Author

Great, thanks!

@martinholters martinholters merged commit 1e623ad into JuliaLang:master Aug 7, 2024
21 checks passed
@MilesCranmer MilesCranmer deleted the FixN branch August 7, 2024 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Fix{N} utility for fixing an argument
3 participants