You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This replaces `Fix` (xref #54653) with `fix`. The usage is similar: use
`fix(i)(f, x)` instead of `Fix{i}(f, x)`.
Benefits:
* Improved type safety: creating an invalid type such as
`Fix{:some_symbol}` or `Fix{-7}` is not possible.
* The design should be friendlier to future extensions. E.g., suppose
that publicly-facing functionality for fixing a keyword (instead of
positional) argument was desired, it could be achieved by adding a
new method to `fix` taking a `Symbol`, instead of adding new public
names.
Lots of changes are shared with PR #56425, if one of them gets merged
the other will be greatly simplified.
function Base.show((@nospecialize io::Base.IO), @nospecialize unused::Type{PartiallyAppliedFunction{Position}}) where {Position <:_TypeDomainNumbers.PositiveIntegers.PositiveInteger}
1176
+
if Position isa DataType
1177
+
print(io, "fix(")
1178
+
show(io, Position.instance)
1179
+
print(io, ')')
1180
+
else
1181
+
show(io, PartiallyAppliedFunction)
1182
+
print(io, '{')
1183
+
show(io, Position)
1184
+
print(io, '}')
1185
+
end
1186
+
end
1187
+
1188
+
function Base.show((@nospecialize io::Base.IO), @nospecialize p::PartiallyAppliedFunction)
* Its instances are partial applications of the function, with one positional argument fixed. The argument to `fix` is the one-based index of the position argument to be fixed.
1220
+
1221
+
For example, `fix(3)(f, x)` behaves similarly to `(y1, y2, y3...; kws...) -> f(y1, y2, x, y3...; kws...)`.
1158
1222
1159
-
A type representing a partially-applied version of a function `f`, with the argument
1160
-
`x` fixed at position `N::Int`. In other words, `Fix{3}(f, x)` behaves similarly to
0 commit comments