Closure without mutation or re-assignment ("pure"):
const addSome = (x) => (y) => x + y; const addFive = addSome(5); addFive(1) === addFive(1)
Closure with re-assignment += ("not pure"):
+=
const counter = (x) => (y) => x += y; const countFromZero = counter(0); countFromZero(1) !== countFromZero(1)
My point is that there is nothing wrong with closures. It is re-assignment and mutation which make closures (or functions) "not pure".
Yup, makes sense!
Re state: in pure FP I think we mean a "named" piece of data whose instances get changed over time:
go :: Int -> Int go 0 = 0 go s = s + go (s-1)
Here s can be thought of as state, even though specific bindings of s don't change.
s
We observe state over the course of computation.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Closure without mutation or re-assignment ("pure"):
Closure with re-assignment
+=
("not pure"):My point is that there is nothing wrong with closures. It is re-assignment and mutation which make closures (or functions) "not pure".
Yup, makes sense!
Re state: in pure FP I think we mean a "named" piece of data whose instances get changed over time:
Here
s
can be thought of as state, even though specific bindings ofs
don't change.We observe state over the course of computation.