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
16 changes: 14 additions & 2 deletions src/FixFunctionArgument.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module FixFunctionArgument
end
end
function get_n(::Fix{N}) where {N}
check_positive(N) - 1
check_positive(N)
end
# Properties for compatility with `Base.Fix`
const property_name_f = :f
Expand All @@ -104,7 +104,7 @@ module FixFunctionArgument
end
# Make `Fix` callable
function (fix::Fix)(args::Vararg{Any, TupleLength}; kwargs...) where {TupleLength}
n = get_n(fix)
n = get_n(fix) - 1
if length(args) < n
throw_too_few_args()
end
Expand All @@ -124,6 +124,18 @@ module FixFunctionArgument
fixed_argument = fix.x
callable(arg, fixed_argument; kwargs...)
end
function Base.show(io::IO, fix::Fix)
n = get_n(fix)
callable = fix.f
fixed_argument = fix.x
show(io, Fix{n})
print(io, '(')
show(io, callable)
print(io, ',')
print(io, ' ')
show(io, fixed_argument)
print(io, ')')
end
"""
Fix1

Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ using Test
@test_throws Exception fixed.z
end
end
@testset "two-argument `show` roundtripping" begin
for N ∈ (1, 2, 3, 999)
for x ∈ (Fix{N}(convert, Float32), Fix{N}(Int, 7))
@test x === (eval ∘ Meta.parse ∘ repr)(x)
end
let x = Fix{N}(Int, big(7))
@test repr(x) == (repr ∘ eval ∘ Meta.parse ∘ repr)(x)
end
end
end
end

using Aqua: Aqua
Expand Down