# Proposal to add Extension Methods to the language

**URL:** <https://contributors.scala-lang.org/t/proposal-to-add-extension-methods-to-the-language/2945>\
**Category:** Scala Improvement Process\
**Created:** [March 18, 2019, 2:00pm UTC](https://contributors.scala-lang.org/t/proposal-to-add-extension-methods-to-the-language/2945 "2019-03-18T14:00:59Z")\
**Posts on this page:** 1\
**Showing post:** 31

<div class="post-metadata">

**Author:** ![sideeffffect](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/sideeffffect/32/1466_2.png) [@sideeffffect](https://contributors.scala-lang.org/u/sideeffffect)\
**Post date:** [June 27, 2019, 1:12pm UTC](https://contributors.scala-lang.org/t/proposal-to-add-extension-methods-to-the-language/2945/31 "2019-06-27T13:12:07Z")

</div>

I think this is a great approach to extension methods, and it would ultimately simplify Scala.

There would be 2 ways to do it.

More focused one (only for case where the first parameter block has one member):

```auto
case class A(...)
def f(a: A)(b: B, c: C): D = ...
a.f(b, c) // de-sugars to f(a)(b, c)

```

Broader one:

```auto
case class A(...)
def f(a: A, b: B, c: C): D = ...
a.f(b, c) // de-sugars to f(a, b, c)

```

Currently there is a tension between _function application_ and _method selection and call_. This would basically make the distinction almost meaningless.

Also, currently function application is not very practical (annoying, actually) in contrast to _method selection and call_, because it requires nesting parentheses:

```auto
f(g(h(x))) // nested parentheses, so ugly and annoying to write

```

is not as elegant as

```auto
x.h.g.f

```

There is this problem of applying function to an argument, but without any “nesting” in the syntax, like `(` and `)`.  
Other languages deal with this in their own way.

F# (and many others) has `|>` operator

```auto
x |> h |> g |> f

```

Haskell has `$`

```auto
f . g . h $ x
-- or
f $ g $ h $ x

```

There is a language called [Koka](https://koka-lang.github.io/koka/doc/kokaspec.html#sec-dot) which does something like was proposed above

```auto
a.f(b, c) ~~> f(a, b, c)

```

I see 2 benefits in adopting this extension methods approach:

1. simplifying syntax (the necessity of nesting () is a wart IMHO)
2. decrease the difference between thinking of and using functions vs methods

If Scala adopted this, it would even more unify functions and methods, which would be a solution true to Scala’s mission to marry functional and object-oriented programming.

---

_[View the full topic](https://contributors.scala-lang.org/t/proposal-to-add-extension-methods-to-the-language/2945)._
