# Enlistment for corsairing the map function (in REPL/Main only)

**URL:** <https://discourse.julialang.org/t/enlistment-for-corsairing-the-map-function-in-repl-main-only/96768>\
**Category:** General Usage\
**Created:** [March 29, 2023, 9:58am UTC](https://discourse.julialang.org/t/enlistment-for-corsairing-the-map-function-in-repl-main-only/96768 "2023-03-29T09:58:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin.auer](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@martin.auer](https://discourse.julialang.org/u/martin.auer)\
**Post date:** [March 29, 2023, 9:58am UTC](https://discourse.julialang.org/t/enlistment-for-corsairing-the-map-function-in-repl-main-only/96768/1 "2023-03-29T09:58:51Z")

</div>

Hi,

I am toying with a module that end users are supposed to mainly be using via the Julia REPL, to leverage its piping capabilities.

In this specific tool’s REPL context, I would like to find a (somewhat safe, somewhat sanctionable) way to buccaneer `map(f)` to make it currying (thus avoiding to introduce a new function+name for that purpose), i.e.,

```julia
[1,2,3] |> map(x->x^2)

```

should work. (This is unlikely to be done in Julia, as, unlike the upcoming `filter`, corner cases of map’s current behavior exist.)

Any ideas would be much appreciated! Any other packages should be unaffected, as we want to avoid outright piracy. (Again, just the REPL use, the end user typing/memorizing experience, would be the goal here.)

My main two ideas would have been:

1. Somehow “un-export” Base.map from Main:  
…but I found no way of removing the Main.map (alias?) from the (I suppose) “REPL module scope” `Main`.

2. Check for input argument count  
I thought of overwriting the current `map(f::Any)=f()`, and testing for number of arguments – then either follow the original map behavior for a function that has a method with 0 args (it would fail otherwise anyway), or simple curry. Still fiddling with that… maybe via the `sig` field of all methods? (In this tool’s context, end users are highly unlikely to ever need or define zero-arg functions.)

(I am aware that even if a safe, REPL-only map-loot exists, that it might be considered dubious to “teach” non-standard map bahavior to users. In this specific case, end users are from a different profession, and unlikely to be exposed to this corner case map behavior in later/other Julia contexts.)

Thanks!  
Martin

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [March 29, 2023, 1:29pm UTC](https://discourse.julialang.org/t/enlistment-for-corsairing-the-map-function-in-repl-main-only/96768/2 "2023-03-29T13:29:52Z")

</div>

If you define `map` before you use it, then `Base.map` will never be imported. You could put this in `startup.jl`.

```julia
$ julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.9.0-beta3 (2023-01-18)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> map(f) = x->Base.map(f, x)
map (generic function with 1 method)

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

julia> Base.map == map
false

julia> Base.map == Main.map
false

```

You could even create a package as follows.

```julia
$ julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.9.0-beta3 (2023-01-18)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> baremodule MyPkg
           import Base
           export map
           map(f) = x->Base.map(f, x)
       end
Main.MyPkg

julia> import .MyPkg: map

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

julia> @which map
Main.MyPkg

```

---

<div class="post-metadata">

**Author:** ![martin.auer](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@martin.auer](https://discourse.julialang.org/u/martin.auer)\
**Post date:** [March 29, 2023, 1:51pm UTC](https://discourse.julialang.org/t/enlistment-for-corsairing-the-map-function-in-repl-main-only/96768/3 "2023-03-29T13:51:56Z")

</div>

Thar she blows!! Simply brilliant; thank you very much!
