Question: I have a function like that:

```
function intiFun(initValue) {

    const firstResult = firstFun(initValue);
    const secondResult = secondFun(firstResult);
    const thirdResult = thirddFun(secondResult);
    const fourthResult = fourthFun(thirdResult);
    return fourthResult;
}

```

but i want to write it better. and i dont want to save value from each function as variable.

is there any solution to to call functions with out save old value

like rxjs or somthing like that: 

```
function intiFun(initValue) {
    return firstFun(initValue).secondFun().thirddFun().fourthFun();
}

```

or more better like that:

```
function intiFun(initValue) {
    return firstFun(initValue)         
          .secondFun(secondInput)
          .thirddFun(secondInput)
          .fourthFun(secondInput)
}

function secondFun(value, secondInput) {
    return ...;
}
...

```

or some liberally to do that (maybe lodash)

Answer: 
`pipe`, manual currying & partial application to the rescue:

```js
const pipe = funs => x =>
  funs.reduce ((o, fun) => fun (o), x)

const f = x => x + 1
const g = x => y => x + y * 2
const h = x => x * x
const i = x => y => z => x + y / z + 3
const j = x => x + 5

const init = pipe ([
   f
  ,g (4)
  ,h
  ,i (10) (33)
  ,j
])

const input = 1
const output = init (input)

console.log (output)
```
```
const firstFun  = x => { /* return ... */ };
const secondFun = x => { /* return ... */ };
const thirdFun  = x => { /* return ... */ };
const fourthFun = x => { /* return ... */ };

const callAll= (value, ...functions) => {
   functions.forEach(fn => value = fn(value));
   retrun value;
}

const result = callAll(3, firstFun, secondFun, thirdFun, fourthFun);

console.log(result);

```