Yes. It is guaranteed to be clean.
The reason is that it depends only on bound and unchanged free variables.
However, this code violates the rule of access to external functions of the sphere.
, , . , , .. .
Haskell , foldr, , , , .
, - . parseInt - , , - , , , .
parseInt , , -, , , .
, . . .
function compose(f2, f1) {
return (...args) => f2(f1(...args));
}
function makeAdder(initialValue) {
return v => v + initialValue;
}
const add11 = compose(makeAdder(10), makeAdder(1));
add11(5);
. / f1, f2, initialValue . add11 - .
compose. , . , .
OO !
, .
class FunctionalNumber {
constructor(value) {
this.value = value;
}
add(fn) {
return new FunctionalNumber(this.value + fn.value);
}
sub(fn) {
return new FunctionalNumber(this.value - fn.value);
}
}
.
obj.someMethod(arg1, arg2) obj someFunction(obj, arg1, arg2). , someFunction mutated obj, , . someMethod obj.
, , , , . Haskell Lisp. JavaScript:
class Cons {
constructor(car, cdr) {
this.car = car;
this.cdr = cdr;
}
}
const lst = new Cons(1, new Cons(2, new Cons(3, null)));
const lst0 = new Cons(0, lst);
lst0 lst, . lst0 lst. , . 50- .