@@ -1185,26 +1185,33 @@ end
1185
1185
(f:: Fix2 )(y) = f. f (y, f. x)
1186
1186
1187
1187
"""
1188
- FixN(f, Val(N), x...)
1188
+ Fix(f, n, x...)
1189
+ Fix(f, Val(n), x...)
1189
1190
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]...)`.
1193
1194
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.
1196
1200
"""
1197
- struct FixN {F,N,T<: Tuple } <: Function
1201
+ struct Fix {F,N,T<: Tuple } <: Function
1198
1202
f:: F
1199
1203
x:: T
1200
1204
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))
1203
1207
end
1204
1208
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}
1206
1213
@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) `" ))
1208
1215
return f. f (args[begin : begin + (N- 2 )]. .. , f. x... , args[begin + (N- 1 ): end ]. .. )
1209
1216
end
1210
1217
0 commit comments