Allowing the object.method(args...) syntax as an alias for method(object, args ...)

Looking at Base.Fix1 and Base.Fix2, there’s a lot of overlap between the proposed operators and the internal fix functions. If Fix1 were opened up to accepting more than one argument, it’d be completely equivalent to />. And for two-argument functions, \> is equivalent to Fix2. In other words, the proposed operators /> and \> are simply the logical extension of Fix1 and Fix2.

The only thing missing would be parametric types. Perhaps introduce parametric types FixFirst and FixLast, and then make /> and \> syntax sugar for them?

For example, in namedtuples.jl line 104 I see:

NamedTuple{names, T}(map(Fix1(getfield, nt), names))

with the proposed operators this could be written as

NamedTuple{names, T}(map(nt/>getfield, names))

and presumably, you’d see something like this:

julia> nt = (a=1, b=1.0);

julia> typeof(nt/>getfield)
Base.FixFirst{typeof(getfield), NamedTuple{(:a, :b), Tuple{Int64, Float64}}}

julia> nt/>getfield(:b)
1.0

similar for \> of course:

julia> arr = [1, 2, 3];

julia> typeof(arr\>map)
Base.FixLast{typeof(map), Vector{Int64}}

julia> arr\>map(x->x^2)
3-element Vector{Int64}:
 1
 4
 9

As mentioned, having a parametric type that embodies partial application

One can also conceive a Base.Fix{n} where {n isa Int} type… or for the truly deranged, Base.Fix{k} where {k isa Symbol} for currying into keyword arguments. I’m not sure what’s a good way to make a type that would cover underscore currying. :thinking:

1 Like