https://hackernoon.com/javascript-and-functional-programming-pt-3-pure-functions-d572bb52e21c

 

Javascript and Functional Programming — Pt. 3: Pure Functions

Purity Note: This is part of the “Javascript and Functional Programming” series on learning functional programming techniques in JavaScript ES6+. Check out the Part 4 , on currying function in JS here.To start from the ground up check out Damn, this feels 

hackernoon.com

 

프로그램 버그의 상당수는 I/O, data 변형에서 비롯된다. 이러한 버그들을 최소화 하고싶지 않나?

복잡하고 휘발성 짙은 코드들을 지양하고, 단순하고 직관적이며 결과가 투명한 코드를 위해 탄생한 개념이 바로 Pure Function이다.

같은 인풋을 넣으면 항상 같은 아웃풋을 제공한다. 깔끔하다. 투명하다. pure하다.

const add = (x, y) => x + y // This is a pure function

 

아무튼 pure함수는 테스트에 용이해야하고 가독성이 있어야 하며 항상 투명한 결과를 뱉어야 하고 불변해야 한다.

 

+ Recent posts