Skip to content

Commit c4c9b33

Browse files
committed
rename to Fix function
1 parent b25bb9e commit c4c9b33

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

base/operators.jl

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,26 +1185,33 @@ end
11851185
(f::Fix2)(y) = f.f(y, f.x)
11861186

11871187
"""
1188-
FixN(f, Val(N), x...)
1188+
Fix(f, n, x...)
1189+
Fix(f, Val(n), x...)
11891190
1190-
A type representing a partially-applied version of a function
1191-
`f`, with the argument or arguments "x" inserted at the `N`th position. In other words,
1192-
`FixN(f, Val(N), x1, x2)` behaves similarly to `(y...,) -> f(y[1:N-1]..., x1, x2, y[N:end]...)`
1191+
A type representing a partially-applied version of a function `f`, with the argument or
1192+
arguments "x" inserted at the `n`th position. In other words, `Fix(f, Val(n), x1, x2)`
1193+
behaves similarly to `(y...,) -> f(y[1:n-1]..., x1, x2, y[n:end]...)`.
11931194
1194-
You may also pass a number of arguments to `FixN`, with `Val(N)`, in which case they will
1195-
be inserted at position `N`, `N+1`, and so forth.
1195+
You may also pass a number of arguments to `Fix`, with `Val(n)`, in which case they will
1196+
be inserted at position `n`, `n+1`, and so forth.
1197+
1198+
`Val(n)` is preferred for type stability, though `n` as an argument is provided
1199+
for convenience.
11961200
"""
1197-
struct FixN{F,N,T<:Tuple} <: Function
1201+
struct Fix{F,N,T<:Tuple} <: Function
11981202
f::F
11991203
x::T
12001204

1201-
FixN(f::F, ::Val{N}, x, xs...) where {F,N} = (xt=(x, xs...); new{F,N,_stable_typeof(xt)}(f, xt))
1202-
FixN(f::Type{F}, ::Val{N}, x, xs...) where {F,N} = (xt=(x, xs...); new{F,N,_stable_typeof(xt)}(f, xt))
1205+
Fix(f::F, ::Val{N}, x, xs...) where {F,N} = (xt=(x, xs...); new{F,N,_stable_typeof(xt)}(f, xt))
1206+
Fix(f::Type{F}, ::Val{N}, x, xs...) where {F,N} = (xt=(x, xs...); new{F,N,_stable_typeof(xt)}(f, xt))
12031207
end
12041208

1205-
function (f::FixN{F,N,T})(args::Vararg{Any,M}) where {F,N,T,M}
1209+
Fix(f::F, n::Int, x, xs...) where {F} = Fix(f, Val(n), x, xs...)
1210+
Fix(f::Type{F}, n::Int, x, xs...) where {F} = Fix(f, Val(n), x, xs...)
1211+
1212+
function (f::Fix{F,N,T})(args::Vararg{Any,M}) where {F,N,T,M}
12061213
@inline
1207-
M < N - 1 || throw(ArgumentError("expected at least $(N-1) arguments to a `FixN` function with `N=$(N)`"))
1214+
M < N - 1 || throw(ArgumentError("expected at least $(N-1) arguments to a `Fix` function with `N=$(N)`"))
12081215
return f.f(args[begin:begin+(N-2)]..., f.x..., args[begin+(N-1):end]...)
12091216
end
12101217

0 commit comments

Comments
 (0)