# Underscore currying in 1.2?

**URL:** <https://discourse.julialang.org/t/underscore-currying-in-1-2/22209>\
**Category:** Internals & Design\
**Created:** [March 22, 2019, 5:54pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209 "2019-03-22T17:54:24Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [March 22, 2019, 5:54pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/1 "2019-03-22T17:54:24Z")

</div>

I was wondering what the prospects were of [this](https://github.com/JuliaLang/julia/pull/24990) being resurrected for 1.2. I notice it was on the milestones, but it seemed to me there was a bit of skepticism and I’m not sure what its status is.

I have to admit, I have an irrationally strong desire to have this, and I would probably use it all the time (likely to the point of abuse).

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [March 22, 2019, 6:25pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/2 "2019-03-22T18:25:49Z")

</div>

As I understand it:

1.x releases happen on a schedule. (IIRC every 4 months?)  
Since at any point in time _master_ both builds and does not contain any breaking changes.  
What ever is in master at that point in time, is going to be in 1.x.

This is in contrast to 0.x releases which were basically planned major releases.  
Each release was done when all the desired features were done.

As such the question of if X will be in a release is less one of planning,  
and more one of what gets done.

BTW: I am also mad keen on that feature.

---

<div class="post-metadata">

**Author:** ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Post date:** [March 22, 2019, 6:52pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/3 "2019-03-22T18:52:52Z")

</div>

So is this feature done? or what else need to make it done? I don’t quite get what’s happening now…

---

<div class="post-metadata">

**Author:** ![00vareladavid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/00vareladavid/32/23521_2.png) [@00vareladavid](https://discourse.julialang.org/u/00vareladavid)\
**Post date:** [March 22, 2019, 7:57pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/4 "2019-03-22T19:57:32Z")

</div>

I instinctively reach for this all the time! Only to remember that it is not available yet 😭

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [March 22, 2019, 11:02pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/5 "2019-03-22T23:02:11Z")

</div>

In short it is more complex than it looks.  
Since most solutions have uninutive edge cases.

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [March 22, 2019, 11:06pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/6 "2019-03-22T23:06:44Z")

</div>

> [@oxinabox](#):
>
> In short it is more complex than it looks.

Can anybody distill the essence of whatever was the main objection for me? I don’t exactly feel clear-headed about it after reading the PR thread.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [March 23, 2019, 1:46am UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/7 "2019-03-23T01:46:02Z")

</div>

Inability to come to a consensus on what a good rule is for what expression is “consumed by” underscores and becomes the function body.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [March 23, 2019, 7:41am UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/8 "2019-03-23T07:41:01Z")

</div>

Looking at the voting on comments on that issue they look pretty unanimous. It’s certainly an awesome idea.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 23, 2019, 8:28am UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/9 "2019-03-23T08:28:48Z")

</div>

I too am irrationally eager to have this. I think it’s especially nice for the simple cases where it streamlines the expression considerably. In the more complicated cases, one might as well use ordinary notation.

---

<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:** [March 23, 2019, 1:52pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/10 "2019-03-23T13:52:09Z")

</div>

I was initially (irrationally? 😉) eager for this, then after reading about and digesting the corner cases I realized that I would almost always prefer lambdas: for simple cases they work fine, for complex cases I would be scratching my head about corner cases of `_` syntax.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 23, 2019, 4:01pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/11 "2019-03-23T16:01:36Z")

</div>

I think we came to a rough consensus on what the rule should be, but it still needs to be implemented. (The current PR implements a simpler rule, but we decided on something a bit more ambitious to make it easier to use binary/unary operators.) I haven’t gotten around to working on it.

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [March 25, 2019, 1:25pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/12 "2019-03-25T13:25:32Z")

</div>

I’m still not sure I understand what the edge cases are that would cause so much ambiguity, but I do think that the way `Base` and much of the Julia package ecosystem are written promote the tendency to reach for this feature quite often, especially in it’s simplest form. I find myself quite frequently making calls like

```julia
findall(myfunction(a, _, c), iter)

```

or

```julia
sort!(x, by=myfunction(_, b))

```

Unless I’m missing something big, those are not cases that cause much ambiguity, and occur frequently. Those examples look a lot cleaner and more readable than `x -> myfunction(a, x)` to me. (Not to mention that it’s only it’s not until 1.2 that we get the remaining relational operator currying).

Anyway, if I’m reading the sentiment right, it’s sounding like nobody is entirely opposed to the existence of this feature, so sounds like we’ll have it eventually, even if not in 1.2.

---

<div class="post-metadata">

**Author:** ![dave.f.kleinschmidt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dave.f.kleinschmidt/32/55_2.png) [@dave.f.kleinschmidt](https://discourse.julialang.org/u/dave.f.kleinschmidt)\
**Post date:** [March 28, 2019, 4:26pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/13 "2019-03-28T16:26:01Z")

</div>

I don’t have much to add here except that I’m also extremely eager to have something like this. I got so used to piping everything in R (which, you may agree or disagree with, but I Love) that I really miss it when I’m working with Julia.

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [March 28, 2019, 4:31pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/14 "2019-03-28T16:31:26Z")

</div>

I’ve given it a little bit more thought: the only case in which I think I’d get tripped up is _nested_ currying. As in, what is

```julia
f(g(_))

```

I suppose that has to lower to `f(g)` and not `x -> f(g(x))`. Still, I can definitely live with that.

---

<div class="post-metadata">

**Author:** ![dave.f.kleinschmidt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dave.f.kleinschmidt/32/55_2.png) [@dave.f.kleinschmidt](https://discourse.julialang.org/u/dave.f.kleinschmidt)\
**Post date:** [March 28, 2019, 4:35pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/15 "2019-03-28T16:35:55Z")

</div>

Could you summarise what those rules would be, or point to a comment in the issue that summarises them? I haven’t been keeping up and didn’t see in a quick skim.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 28, 2019, 6:48pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/16 "2019-03-28T18:48:45Z")

</div>

> [@dave.f.kleinschmidt](#):
>
> Could you summarise what those rules would be, or point to a comment in the issue that summarises them?

Basically this comment, plus some subsequent clarifications of edge cases: [RFC: curry underscore arguments to create anonymous functions by stevengj · Pull Request #24990 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/24990#issuecomment-443247756)

---

<div class="post-metadata">

**Author:** ![Orbots](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orbots/32/3392_2.png) [@Orbots](https://discourse.julialang.org/u/Orbots)\
**Post date:** [March 29, 2019, 5:56pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/17 "2019-03-29T17:56:57Z")

</div>

You can cover quite a few cases with a `partial` function. Then try to write your functions so the thing you most often want to “curry” is first in the parameter list. Which is the case for many functions ( map, reduce, etc ). I also have a `swap` function if it happens to be in the second position.

```
partial = (f::Function,y...)->(z...)->f(y...,z...)
# too cheeky?
∂(f::Function,y...) = partial(f,y...)
swap(f::Function) = (a,b...)->f(b...,a)

double = ∂(map, ∂((*), 2))

```

I’m definitely looking forwards to the \_ feature though! Always better to use something standard.

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [March 29, 2019, 8:24pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/18 "2019-03-29T20:24:58Z")

</div>

That’s a cool idea. Of course, instead of `∂` you could always use the `\:curry:` (🍛) emoji 😉

---

<div class="post-metadata">

**Author:** ![Orbots](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orbots/32/3392_2.png) [@Orbots](https://discourse.julialang.org/u/Orbots)\
**Post date:** [March 30, 2019, 12:56am UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/19 "2019-03-30T00:56:26Z")

</div>

I couldn’t resist a coding related pun. Also, because friday.

I guess you could say I got curried away.

> **[GitHub - Orbots/Curry.jl: Currying for Julia](https://github.com/Orbots/Curry.jl)**
>
> Currying for Julia. Contribute to Orbots/Curry.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![vvjn](https://avatars.discourse-cdn.com/v4/letter/v/5f9b8f/32.png) [@vvjn](https://discourse.julialang.org/u/vvjn)\
**Post date:** [March 31, 2019, 4:59pm UTC](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209/20 "2019-03-31T16:59:48Z")

</div>

Has anyone tried Elixir’s way to do short anonymous functions? It looks like `&(&1 + &2)` for `(x,y) -> x+y`. So, where the expression stops is pretty explicit.

[Next page](https://discourse.julialang.org/t/underscore-currying-in-1-2/22209.md?page=2)
