Map as a partial function


#1

Currently in Julia v0.7.0 we have

julia> [1,2,3] |> map(x->x*x)
ERROR: MethodError: no method matching (::getfield(Main, Symbol("##3#4")))()
Closest candidates are:
  #3(::Any) at REPL[0]:1
Stacktrace:
 [1] map(::getfield(Main, Symbol("##3#4"))) at .\abstractarray.jl:2033
 [2] top-level scope at none:0

But if I define

julia> Base.map(f::Function) = Base.Fix1(Base.map,f)

the results are

julia> [1,2,3] |> map(x->x*x)
3-element Array{Int64,1}:
 1
 4
 9

The latter seems useful.
Any change map(f::Function) = Fix1(map,f) could be added to Base.operators.jl ?


#2

I think the long-term plan is to have syntax for partial application, see

for a recent discussion.


#3

Why not

[1,2,3] .|> x->x^2

#4

That works. Clever and more straight forward. Didn’t know you could do that.


#5

I’ve been noticing more and more that broadcast has been replacing many traditional uses of map. Obviously, they’re not completely equivalent, but for the large number of cases where they are, broadcast seems to be the emerging consensus of the Julia community (and, as far as I know, one of the first examples of a uniquely “Julian” style).