# Arrow function declaration

Bergi a.d.bergi at web.de
Mon Oct 26 14:44:44 UTC 2015

```Федор Неживой schrieb:
> I'm looking for a champion for
> https://github.com/gyzerok/ecmascript-arrow-function-declaration

Your proposal doesn't seem to solve the problem that you gave in your
rationale. Let me paraphrase:

You've got curried functions, and you want to partially apply them
declaratively without caring for order.
```js
// does not work
const sumOfSquares = compose(sum, squares);
const sum = reduce((x, y) => x + y, 0);
const squares = map(x => x * x);
```
```js
// would work because of hoisting:
function sumOfSquares(xs) { return compose(sum, squares)(xs); }
function sum(xs) { return reduce((x, y) => x + y, 0)(xs); }
function squares(xs) { return map(x => x * x); }
```

Now you are proposing some kind of "arrow declaration" that desugars to
a function declaration. This makes no sense. The non-working code
doesn't benefit of that in any way - there are no arrows function, only
function calls.

What you are *actually* looking for seems to be a lazy initialisation of
variables - the variable declaration is hoisted just as usual, but the
initialiser would run when the variable is used the first time.
The following would be what I'd envision to solve your problem:
```js
// does work
lazy sumOfSquares = compose(sum, squares);
lazy sum = reduce((x, y) => x + y, 0);
lazy squares = map(x => x * x);
```
where `lazy` would work pretty much like a `lazy val` in Scala.

Regards,
Bergi
```