# Map as a partial function

**URL:** <https://discourse.julialang.org/t/map-as-a-partial-function/12022>\
**Category:** Internals & Design\
**Created:** [June 28, 2018, 3:17am UTC](https://discourse.julialang.org/t/map-as-a-partial-function/12022 "2018-06-28T03:17:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jandehaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jandehaan/32/6805_2.png) [@jandehaan](https://discourse.julialang.org/u/jandehaan)\
**Post date:** [June 28, 2018, 3:17am UTC](https://discourse.julialang.org/t/map-as-a-partial-function/12022/1 "2018-06-28T03:17:47Z")

</div>

Currently in Julia v0.7.0 we have

```julia
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
julia> Base.map(f::Function) = Base.Fix1(Base.map,f)

```

the results are

```julia
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 ?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 28, 2018, 5:54am UTC](https://discourse.julialang.org/t/map-as-a-partial-function/12022/2 "2018-06-28T05:54:17Z")

</div>

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

[https://github.com/JuliaLang/julia/pull/24990](https://github.com/JuliaLang/julia/pull/24990)

for a recent discussion.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [June 28, 2018, 7:46am UTC](https://discourse.julialang.org/t/map-as-a-partial-function/12022/3 "2018-06-28T07:46:37Z")

</div>

Why not

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

```

---

<div class="post-metadata">

**Author:** ![jandehaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jandehaan/32/6805_2.png) [@jandehaan](https://discourse.julialang.org/u/jandehaan)\
**Post date:** [June 28, 2018, 12:41pm UTC](https://discourse.julialang.org/t/map-as-a-partial-function/12022/4 "2018-06-28T12:41:57Z")

</div>

> [@dlfivefifty](#):
>
> [1,2,3] .|\> x-\>x^2

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

---

<div class="post-metadata">

**Author:** ![jballanc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jballanc/32/328_2.png) [@jballanc](https://discourse.julialang.org/u/jballanc)\
**Post date:** [June 29, 2018, 10:04pm UTC](https://discourse.julialang.org/t/map-as-a-partial-function/12022/5 "2018-06-29T22:04:01Z")

</div>

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).
