33. 5. Closure
• 내부에서 참조되는 모든 인수에 대한 묵시적 바인딩을
지닌 함수를 말함
• 자신이 참조하는 문맥(context)를 포함한다
• C++11에서는 람다 표현식으로 생성
• 다만 람다 밖의 변수는 Capture를 통해 접근
• 이해가 잘 안되면 Functor를 생각하면 됨
36. 6. Pure function
• 함수의 결과값이 오직 입력 인자 값들에 의해서만 결정
• Side effects가 없음
int abs(int n);
int atoi(const char *str);
int getDefaultPort(bool https) {
return https ? 443 : 80;
}
int rand();
time_t time (time_t* timer);
bool g_https = false;
int getDefaultPort() {
return g_https ? 443 : 80;
}
37. 6. Pure function
• 참조 투명성을 가짐
- 어떤 표현식을 그 표현식의 결과값으로 교체해도
전체 프로그램의 실행결과에 영향을 주지 않는 성질
• 컴파일러에게 다양한 최적화 기회를 제공
- Memoization
- Lazy evaluation
39. 불변성
• 내용의 변경은 새로운 객체를 생성할 때만 가능
• 생성, 테스트, 사용법이 단순하고 쉬움
• Thread-Safe
• 쉬운 캐쉬 – 이름이 같으면 내용도 같음
• Temporal coupling 줄임
• Identity mutability problem 없음
59. 출처
• Functional Reactive Programming With RxSwift
- https://www.slideshare.net/sunhyouplee/functional-reactive-programming-with-rxswift-62123571
• NDC14 - Rx와 Functional Reactive Programming으로 고성능 서버 만들기
- https://www.slideshare.net/jongwookkim/ndc14-rx-functional-reactive-programming
• 더 좋은 코드를 위한 함수형 프로그래밍
- https://www.slideshare.net/isaacjeon/ndc17-ppt-fpinmodernc
• 위키피디아 Functional programming
- https://en.wikipedia.org/wiki/Functional_programming
• 위키피디아 Persistent data structure
- https://en.wikipedia.org/wiki/Persistent_data_structure
• 클로저라는 훌륭한 도구와 영속 불변 자료 구조
- goo.gl/m6aAWN
• 값중심의 프로그래밍
- http://ropas.snu.ac.kr/~kwang/paper/maso/1.pdf
60. 출처
• Nested function
- http://ajaxlab.net/?p=182
• 함수형 프로그래머가 되고 싶다고? (Part 1~6)
- goo.gl/CWyhjd
• 나무위키 메모이제이션
- https://namu.wiki/w/%EB%A9%94%EB%AA%A8%EC%9D%B4%EC%A0%9C%EC%9D%B4%EC%85%98
• 함수형 사고
- http://www.hanbit.co.kr/store/books/look.php?p_code=B6064588422