SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Downloaden Sie, um offline zu lesen
Pure Function and Honest Design
고형호
hyungho.ko@gmail.com
04/10/2017
http://www.slideshare.net/HyungHoKo
순수 함수와 정직한 설계
1. 수학과 프로그래밍 언어
2. 함수
3. 치환
4. 함수 합성
5. 함수 조건
6. 사례
1. 수학과 프로그래밍 언어
기계적인 방식만으론 사실인지 판정할 수 없는, 그런 명제가 존재한다.
참과 거짓을 판단할 수 있는 내용
1931
1936
강의 Max Newman
1945
Von Neumann
architecture
Princeton University
Turing machine
Type, Head, Table, State
register
Finite state machine = Lambda calculus
λ𝒙. 𝒕
추천
1930 1936 1940
기계
명령
Turing machine
기계 有
Lambda calculus
계산식 有
식
계산
값
1 + 6
7
기계 無
기계
더 많은 노력?
연산 파워, 컴파일러 파워, …
상태 상태’
변경
연산 파워
컴파일러 파워
수학적 최적화+…
<int>
<double>
2. 함수
부수 효과(Side effects)
집합 X의 각 원소에 집합 Y의 원소가 오직 하나만 대응될 때,
이 대응관계를 X에서 Y로의 함수라고 하고,
f: X → Y 또는 y = f(x)로 나타낸다.
기대 값 외
Foo
null
입력
Foo
출력
Foo f(Foo x)int f(int x)
{
// 공유 변수
}
데이터 레이스
1
2
3
입력
...
1936
8
9
출력
...
예외, 응답 없음
1
2
3
입력
1936
8
?
출력
int f(int x)
{
// 예외
}
...
...
2
3
입력
1936
8
9
출력
1
입력 값 변경
int f(out int x)
...
...
2
3
입력
1936
8
9
출력
1
출력’
출력 외 변경
int f(int x)
{
// 외부 변경
}
...
...
1
2
3
입력
1936
8
9
출력
...
...
수학
수학적
함수
=
함수는 입력과 출력이 있다.
모든 의존성
Read Only
단일 결과
Create
단일 책임
C
R
U
D
reate
ead
pdate
elete
Lock Free
불변
Single Responsibility Principle
부수 효과
無
같은 값
다른 값
같은 값
같은 값
입력
출력
참조
투명성
참조
불투명성
1
2
3
입력
1936
8
9
출력
...
...
집합 X의 각 원소에 집합 Y의 원소가 오직 하나만 대응될 때,
이 대응관계를 X에서 Y로의 함수라고 하고,
f: X → Y 또는 y = f(x)로 나타낸다.
수학
함수의 출력 값은 그 함수에 입력된 인수에만 의존하므로
인수 x에 같은 값을 넣고 함수 f를 호출하면 항상 f(x)라는 결과가 나온다.
A function gives the same value for same arguments.
참조 투명성
Referential transparency
참조 불투명성
Referential opacity
수학적
함수
=
명령형 함수 부수 효과
-
=
1
2
3
입력
1936
8
9
출력
...
...
+
참조 투명성
A function gives
the same value
for same arguments.
= 순수 함수
Pure Function
…
정적 메소드
비순수 함수
DateTime impure = DateTime.Now;
pure1.AddDays(7);
DateTime pure2 = pure1.AddDays(7);
메소드
순수 함수
DateTime pure1 = new DateTime(2016, 9, 28);
Unknown
𝒇Input Output
Input Output
Side
Effect
Known
3. 치환
수학적
함수 = 명령형 함수 부수 효과- 참조 투명성+
값=
일급 시민
First-class citizen
순수 함수=
int x = f(1); = int x = 1936;
치환(Substitution)
변수 = 값;
함수(값);
함수( … ) { return 값; }
함수 (함수);
함수 ( … ) { return 함수; }
변수 = 함수;
일급 시민
함수를 받고/전달할 수 있는 함수?
(일급 시민)
These operations typically include being
passed as an argument,
returned from a function,
and assigned to a variable.
일급 시민
First-class citizen
These operations typically include being
passed as an argument,
returned from a function,
and assigned to a variable. 변수 = 값;
함수(값);
함수( … ) { return 값; }
함수 (함수);
함수 ( … ) { return 함수; }
변수 = 함수;
람다 표현식
Lambada Expression
고차 함수
Higher-Order Function
함수를 받고/전달할 수 있는 함수?
(일급 시민)
double f(int x)
{
return …
}
double f(int x)
{
return …
}
f(int x)
{
return …
}
f(20);
f(x)
{
return …
}
함수는 입력과 출력이 있다.
f(x)
{
…
}
람다 대수는
함수를 단순하게 표현할 수 있도록 하여 '함수의 계산'이라는 개념을
더 깊이 이해할 수 있게 돕는다.
함수가 반드시 이름을 가질 필요는 없다.
(x)
{
…
}
반복
x =>
…
구분
X => …=
= 순수 함수 - 함수 이름람다 표현식
수학적
함수
= 명령형 함수 부수 효과- 참조 투명성+
순수 함수=
값=
일급 시민
First-class citizen
…
수학적
함수
= 명령형 함수 부수 효과- 참조 투명성+
순수 함수=
값=
일급 시민
First-class citizen
함수 (함수);
함수 ( … ) { return 함수; }
변수 = 함수;
일급 시민
고차 함수 = 순수 함수 + 순수 함수 입력 || 순수 함수 출력
OR
the strategy pattern is a software design pattern
that enables an algorithm's behavior to be selected at runtime.
https://en.wikipedia.org/wiki/Strategy_pattern
Vs.
인터페이스
인터페이스
구현 클래스
4. 함수 합성
f f
연결(Flow)할 수 있는 함수는?
int int xf( )
void f( )
void f( )int x
int f( )
f
f
f
f
f f
f
f
f
f
Fluent Interface프로그래밍 언어
함수 합성(Composition)수학
결합 법칙을 만족시킨다.
(2 + 3) + 5 = 2 + (3 + 5)
연산 순서를 따로 지정하지 않아도 모호함 없이 수식의 값이 결정된다.
The builder pattern is an object creation software design pattern.
Instead of using numerous constructors,
the builder pattern uses another object, a builder,
that receives each initialization parameter step by step
and then returns the resulting constructed object at once.
https://en.wikipedia.org/wiki/Builder_pattern
?
https://en.wikipedia.org/wiki/Fluent_interface
a fluent interface (as first coined by Eric Evans and Martin Fowler) is
an implementation of an object oriented API
that aims to provide more readable code.
Domain-Driven Design Refactoring
A fluent interface is normally implemented
by using method cascading (concretely method chaining)
to relay the instruction context of a subsequent call.
Self-Referential
Ex.
Vs.
Vs.
Builder Pattern Builder Pattern + Fluent Interface
You are also a programmer!
Can you understand this sentence?
글쓰기/읽기
글쓰기/읽기
5. 함수 조건
조건도 함수다.
𝒇 𝒙 =
𝑥 + 1
𝑥 + 2
( 𝒙 > 𝟎 )
( 𝒙 < 𝟎 )
int output;
if (x > 0)
output = x + 1;
else if (x < 0)
output = x + 2;
int output = if (x > 0)
output = x + 1;
else if (x < 0)
output = x + 2;
int output = if (x > 0)
return x + 1;
else if (x < 0)
return x + 2;
C
R
U
D
reate
ead
pdate
elete
?
𝒇 𝒙 =
𝑥 + 1
𝑥 + 2
( 𝑥 > 0 )
( 𝑥 < 0 )
With 라이브러리, …
https://github.com/wallymathieu/with
결과 값
조건
6. 사례
flatMap map
Reduce
ByKey
a b a b b a b a b b a b a b bkey
1 1 1 1 1value
a bkey
2 3value
함수 합성
Fluent Interface 일급 시민
First-class citizen

Weitere ähnliche Inhalte

Was ist angesagt?

[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
Seok-joon Yun
 
[C++ korea] effective modern c++ study item 1정은식
[C++ korea] effective modern c++ study item 1정은식[C++ korea] effective modern c++ study item 1정은식
[C++ korea] effective modern c++ study item 1정은식
은식 정
 

Was ist angesagt? (20)

[C++ korea] effective modern c++ study item8~10 정은식
[C++ korea] effective modern c++ study item8~10 정은식[C++ korea] effective modern c++ study item8~10 정은식
[C++ korea] effective modern c++ study item8~10 정은식
 
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
 
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
 
[C++ korea] Effective Modern C++ study item 19 use shared ptr for shared owne...
[C++ korea] Effective Modern C++ study item 19 use shared ptr for shared owne...[C++ korea] Effective Modern C++ study item 19 use shared ptr for shared owne...
[C++ korea] Effective Modern C++ study item 19 use shared ptr for shared owne...
 
C++11
C++11C++11
C++11
 
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
 
Ch11
Ch11Ch11
Ch11
 
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
 
[C++ korea] effective modern c++ study item 14 declare functions noexcept if ...
[C++ korea] effective modern c++ study item 14 declare functions noexcept if ...[C++ korea] effective modern c++ study item 14 declare functions noexcept if ...
[C++ korea] effective modern c++ study item 14 declare functions noexcept if ...
 
[C++ korea] effective modern c++ study item 1정은식
[C++ korea] effective modern c++ study item 1정은식[C++ korea] effective modern c++ study item 1정은식
[C++ korea] effective modern c++ study item 1정은식
 
[C++ korea] effective modern c++ study item 1 understand template type dedu...
[C++ korea] effective modern c++ study   item 1 understand template type dedu...[C++ korea] effective modern c++ study   item 1 understand template type dedu...
[C++ korea] effective modern c++ study item 1 understand template type dedu...
 
C++17 Key Features Summary - Ver 2
C++17 Key Features Summary - Ver 2C++17 Key Features Summary - Ver 2
C++17 Key Features Summary - Ver 2
 
Template at c++
Template at c++Template at c++
Template at c++
 
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
 
[C++ Korea] Effective Modern C++ Study item 24-26
[C++ Korea] Effective Modern C++ Study item 24-26[C++ Korea] Effective Modern C++ Study item 24-26
[C++ Korea] Effective Modern C++ Study item 24-26
 
Ch08
Ch08Ch08
Ch08
 
[C++ korea] Effective Modern C++ 신촌 Study Item20,21,23
[C++ korea] Effective Modern C++ 신촌 Study Item20,21,23[C++ korea] Effective Modern C++ 신촌 Study Item20,21,23
[C++ korea] Effective Modern C++ 신촌 Study Item20,21,23
 
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
 
코딩인카페 C&JAVA 기초과정 C프로그래밍(3)
코딩인카페 C&JAVA 기초과정 C프로그래밍(3)코딩인카페 C&JAVA 기초과정 C프로그래밍(3)
코딩인카페 C&JAVA 기초과정 C프로그래밍(3)
 
코딩인카페 C&JAVA 기초과정 C프로그래밍(2)
코딩인카페 C&JAVA 기초과정 C프로그래밍(2)코딩인카페 C&JAVA 기초과정 C프로그래밍(2)
코딩인카페 C&JAVA 기초과정 C프로그래밍(2)
 

Andere mochten auch

[OpenStack Days 2016] Track4 - OpenNSL으로 브로드콜 기반 네트,워크 스위치 제어하기
[OpenStack Days 2016] Track4 - OpenNSL으로 브로드콜 기반 네트,워크 스위치 제어하기[OpenStack Days 2016] Track4 - OpenNSL으로 브로드콜 기반 네트,워크 스위치 제어하기
[OpenStack Days 2016] Track4 - OpenNSL으로 브로드콜 기반 네트,워크 스위치 제어하기
OpenStack Korea Community
 

Andere mochten auch (20)

Akka Fault Tolerance
Akka Fault ToleranceAkka Fault Tolerance
Akka Fault Tolerance
 
U2 product For Wiseeco
U2 product For WiseecoU2 product For Wiseeco
U2 product For Wiseeco
 
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
 
Global mobile market report
Global mobile market reportGlobal mobile market report
Global mobile market report
 
Docker 로 Linux 없이 Linux 환경에서 개발하기
Docker 로 Linux 없이 Linux 환경에서 개발하기Docker 로 Linux 없이 Linux 환경에서 개발하기
Docker 로 Linux 없이 Linux 환경에서 개발하기
 
Pitfalls of Object Oriented Programming by SONY
Pitfalls of Object Oriented Programming by SONYPitfalls of Object Oriented Programming by SONY
Pitfalls of Object Oriented Programming by SONY
 
2017 k8s and OpenStack-Helm
2017 k8s and OpenStack-Helm2017 k8s and OpenStack-Helm
2017 k8s and OpenStack-Helm
 
1, 빅데이터 시대의 인공지능 문동선 v2
1, 빅데이터 시대의 인공지능 문동선 v21, 빅데이터 시대의 인공지능 문동선 v2
1, 빅데이터 시대의 인공지능 문동선 v2
 
클라우드 네트워킹과 SDN 그리고 OpenStack
클라우드 네트워킹과 SDN 그리고 OpenStack클라우드 네트워킹과 SDN 그리고 OpenStack
클라우드 네트워킹과 SDN 그리고 OpenStack
 
java 8 람다식 소개와 의미 고찰
java 8 람다식 소개와 의미 고찰java 8 람다식 소개와 의미 고찰
java 8 람다식 소개와 의미 고찰
 
141118 최창원 웹크롤러제작
141118 최창원 웹크롤러제작141118 최창원 웹크롤러제작
141118 최창원 웹크롤러제작
 
세션4. 예제로 배우는 스마트 컨트랙트 프로그래밍
세션4. 예제로 배우는 스마트 컨트랙트 프로그래밍세션4. 예제로 배우는 스마트 컨트랙트 프로그래밍
세션4. 예제로 배우는 스마트 컨트랙트 프로그래밍
 
[OpenStack Days 2016] Track4 - OpenNSL으로 브로드콜 기반 네트,워크 스위치 제어하기
[OpenStack Days 2016] Track4 - OpenNSL으로 브로드콜 기반 네트,워크 스위치 제어하기[OpenStack Days 2016] Track4 - OpenNSL으로 브로드콜 기반 네트,워크 스위치 제어하기
[OpenStack Days 2016] Track4 - OpenNSL으로 브로드콜 기반 네트,워크 스위치 제어하기
 
[OpenStack Days Korea 2016] Track3 - OpenStack on 64-bit ARM with X-Gene
[OpenStack Days Korea 2016] Track3 - OpenStack on 64-bit ARM with X-Gene[OpenStack Days Korea 2016] Track3 - OpenStack on 64-bit ARM with X-Gene
[OpenStack Days Korea 2016] Track3 - OpenStack on 64-bit ARM with X-Gene
 
[OpenStack Days Korea 2016] Track2 - 가상화 네트워크와 클라우드간 협업
[OpenStack Days Korea 2016] Track2 - 가상화 네트워크와 클라우드간 협업[OpenStack Days Korea 2016] Track2 - 가상화 네트워크와 클라우드간 협업
[OpenStack Days Korea 2016] Track2 - 가상화 네트워크와 클라우드간 협업
 
세션5. web3.js와 Node.js 를 사용한 dApp 개발
세션5. web3.js와 Node.js 를 사용한 dApp 개발세션5. web3.js와 Node.js 를 사용한 dApp 개발
세션5. web3.js와 Node.js 를 사용한 dApp 개발
 
세션3. geth 클라이언트 실습 및 모니터링과 시각화
세션3. geth 클라이언트 실습 및 모니터링과 시각화세션3. geth 클라이언트 실습 및 모니터링과 시각화
세션3. geth 클라이언트 실습 및 모니터링과 시각화
 
[2017년 5월 정기세미나] Network with OpenStack - OpenStack Summit Boston Post
[2017년 5월 정기세미나] Network with OpenStack - OpenStack Summit Boston Post[2017년 5월 정기세미나] Network with OpenStack - OpenStack Summit Boston Post
[2017년 5월 정기세미나] Network with OpenStack - OpenStack Summit Boston Post
 
[OpenStack Days Korea 2016] Track2 - 아리스타 OpenStack 연동 및 CloudVision 솔루션 소개
[OpenStack Days Korea 2016] Track2 - 아리스타 OpenStack 연동 및 CloudVision 솔루션 소개[OpenStack Days Korea 2016] Track2 - 아리스타 OpenStack 연동 및 CloudVision 솔루션 소개
[OpenStack Days Korea 2016] Track2 - 아리스타 OpenStack 연동 및 CloudVision 솔루션 소개
 
[OpenStack Days Korea 2016] Track2 - 데이터센터에 부는 오픈 소스 하드웨어 바람
[OpenStack Days Korea 2016] Track2 - 데이터센터에 부는 오픈 소스 하드웨어 바람[OpenStack Days Korea 2016] Track2 - 데이터센터에 부는 오픈 소스 하드웨어 바람
[OpenStack Days Korea 2016] Track2 - 데이터센터에 부는 오픈 소스 하드웨어 바람
 

Ähnlich wie Pure Function and Honest Design

자바스크립트 함수
자바스크립트 함수자바스크립트 함수
자바스크립트 함수
유진 변
 
김민욱, (달빛조각사) 엘릭서를 이용한 mmorpg 서버 개발, NDC2019
김민욱, (달빛조각사) 엘릭서를 이용한 mmorpg 서버 개발, NDC2019김민욱, (달빛조각사) 엘릭서를 이용한 mmorpg 서버 개발, NDC2019
김민욱, (달빛조각사) 엘릭서를 이용한 mmorpg 서버 개발, NDC2019
min woog kim
 
SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8
Sangmin Lee
 

Ähnlich wie Pure Function and Honest Design (20)

함수적 사고 2장
함수적 사고 2장함수적 사고 2장
함수적 사고 2장
 
스칼라와 스파크 영혼의 듀오
스칼라와 스파크 영혼의 듀오스칼라와 스파크 영혼의 듀오
스칼라와 스파크 영혼의 듀오
 
Functional Kotlin makes Kotlin functional
Functional Kotlin makes Kotlin functionalFunctional Kotlin makes Kotlin functional
Functional Kotlin makes Kotlin functional
 
자바스크립트 함수
자바스크립트 함수자바스크립트 함수
자바스크립트 함수
 
파이썬+함수이해하기 20160229
파이썬+함수이해하기 20160229파이썬+함수이해하기 20160229
파이썬+함수이해하기 20160229
 
C언어 세미나 - 함수
C언어 세미나 - 함수C언어 세미나 - 함수
C언어 세미나 - 함수
 
강의자료 2
강의자료 2강의자료 2
강의자료 2
 
파이썬 함수 이해하기
파이썬 함수 이해하기 파이썬 함수 이해하기
파이썬 함수 이해하기
 
[Swift] Functions
[Swift] Functions[Swift] Functions
[Swift] Functions
 
06장 함수
06장 함수06장 함수
06장 함수
 
Function & Closure about Swift
Function & Closure about Swift Function & Closure about Swift
Function & Closure about Swift
 
Parallel objects
Parallel objectsParallel objects
Parallel objects
 
헷갈리는 자바스크립트 정리
헷갈리는 자바스크립트 정리헷갈리는 자바스크립트 정리
헷갈리는 자바스크립트 정리
 
김민욱, (달빛조각사) 엘릭서를 이용한 mmorpg 서버 개발, NDC2019
김민욱, (달빛조각사) 엘릭서를 이용한 mmorpg 서버 개발, NDC2019김민욱, (달빛조각사) 엘릭서를 이용한 mmorpg 서버 개발, NDC2019
김민욱, (달빛조각사) 엘릭서를 이용한 mmorpg 서버 개발, NDC2019
 
SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8
 
Reflect package 사용하기
Reflect package 사용하기Reflect package 사용하기
Reflect package 사용하기
 
7가지 동시성 모델 - 3장. 함수형 프로그래밍
7가지 동시성 모델 - 3장. 함수형 프로그래밍7가지 동시성 모델 - 3장. 함수형 프로그래밍
7가지 동시성 모델 - 3장. 함수형 프로그래밍
 
4.representing data and engineering features(epoch#2)
4.representing data and engineering features(epoch#2)4.representing data and engineering features(epoch#2)
4.representing data and engineering features(epoch#2)
 
Macro & compilation
Macro & compilationMacro & compilation
Macro & compilation
 
Go
GoGo
Go
 

Pure Function and Honest Design

  • 1. Pure Function and Honest Design 고형호 hyungho.ko@gmail.com 04/10/2017 http://www.slideshare.net/HyungHoKo 순수 함수와 정직한 설계
  • 2. 1. 수학과 프로그래밍 언어 2. 함수 3. 치환 4. 함수 합성 5. 함수 조건 6. 사례
  • 4. 기계적인 방식만으론 사실인지 판정할 수 없는, 그런 명제가 존재한다. 참과 거짓을 판단할 수 있는 내용 1931 1936 강의 Max Newman 1945 Von Neumann architecture Princeton University Turing machine Type, Head, Table, State register Finite state machine = Lambda calculus λ𝒙. 𝒕 추천 1930 1936 1940
  • 5. 기계 명령 Turing machine 기계 有 Lambda calculus 계산식 有 식 계산 값 1 + 6 7 기계 無 기계 더 많은 노력? 연산 파워, 컴파일러 파워, … 상태 상태’ 변경
  • 6. 연산 파워 컴파일러 파워 수학적 최적화+… <int> <double>
  • 8. 부수 효과(Side effects) 집합 X의 각 원소에 집합 Y의 원소가 오직 하나만 대응될 때, 이 대응관계를 X에서 Y로의 함수라고 하고, f: X → Y 또는 y = f(x)로 나타낸다. 기대 값 외 Foo null 입력 Foo 출력 Foo f(Foo x)int f(int x) { // 공유 변수 } 데이터 레이스 1 2 3 입력 ... 1936 8 9 출력 ... 예외, 응답 없음 1 2 3 입력 1936 8 ? 출력 int f(int x) { // 예외 } ... ... 2 3 입력 1936 8 9 출력 1 입력 값 변경 int f(out int x) ... ... 2 3 입력 1936 8 9 출력 1 출력’ 출력 외 변경 int f(int x) { // 외부 변경 } ... ... 1 2 3 입력 1936 8 9 출력 ... ... 수학
  • 9. 수학적 함수 = 함수는 입력과 출력이 있다. 모든 의존성 Read Only 단일 결과 Create 단일 책임 C R U D reate ead pdate elete Lock Free 불변 Single Responsibility Principle
  • 10. 부수 효과 無 같은 값 다른 값 같은 값 같은 값 입력 출력 참조 투명성 참조 불투명성 1 2 3 입력 1936 8 9 출력 ... ... 집합 X의 각 원소에 집합 Y의 원소가 오직 하나만 대응될 때, 이 대응관계를 X에서 Y로의 함수라고 하고, f: X → Y 또는 y = f(x)로 나타낸다. 수학 함수의 출력 값은 그 함수에 입력된 인수에만 의존하므로 인수 x에 같은 값을 넣고 함수 f를 호출하면 항상 f(x)라는 결과가 나온다. A function gives the same value for same arguments. 참조 투명성 Referential transparency 참조 불투명성 Referential opacity
  • 11. 수학적 함수 = 명령형 함수 부수 효과 - = 1 2 3 입력 1936 8 9 출력 ... ... + 참조 투명성 A function gives the same value for same arguments. = 순수 함수 Pure Function …
  • 12. 정적 메소드 비순수 함수 DateTime impure = DateTime.Now; pure1.AddDays(7); DateTime pure2 = pure1.AddDays(7); 메소드 순수 함수 DateTime pure1 = new DateTime(2016, 9, 28);
  • 15. 수학적 함수 = 명령형 함수 부수 효과- 참조 투명성+ 값= 일급 시민 First-class citizen 순수 함수= int x = f(1); = int x = 1936; 치환(Substitution) 변수 = 값; 함수(값); 함수( … ) { return 값; } 함수 (함수); 함수 ( … ) { return 함수; } 변수 = 함수; 일급 시민 함수를 받고/전달할 수 있는 함수? (일급 시민) These operations typically include being passed as an argument, returned from a function, and assigned to a variable.
  • 16. 일급 시민 First-class citizen These operations typically include being passed as an argument, returned from a function, and assigned to a variable. 변수 = 값; 함수(값); 함수( … ) { return 값; } 함수 (함수); 함수 ( … ) { return 함수; } 변수 = 함수; 람다 표현식 Lambada Expression 고차 함수 Higher-Order Function 함수를 받고/전달할 수 있는 함수? (일급 시민)
  • 17. double f(int x) { return … } double f(int x) { return … } f(int x) { return … } f(20); f(x) { return … } 함수는 입력과 출력이 있다. f(x) { … } 람다 대수는 함수를 단순하게 표현할 수 있도록 하여 '함수의 계산'이라는 개념을 더 깊이 이해할 수 있게 돕는다. 함수가 반드시 이름을 가질 필요는 없다. (x) { … } 반복 x => … 구분 X => …=
  • 18. = 순수 함수 - 함수 이름람다 표현식 수학적 함수 = 명령형 함수 부수 효과- 참조 투명성+ 순수 함수= 값= 일급 시민 First-class citizen …
  • 19. 수학적 함수 = 명령형 함수 부수 효과- 참조 투명성+ 순수 함수= 값= 일급 시민 First-class citizen 함수 (함수); 함수 ( … ) { return 함수; } 변수 = 함수; 일급 시민 고차 함수 = 순수 함수 + 순수 함수 입력 || 순수 함수 출력 OR
  • 20. the strategy pattern is a software design pattern that enables an algorithm's behavior to be selected at runtime. https://en.wikipedia.org/wiki/Strategy_pattern
  • 23. f f 연결(Flow)할 수 있는 함수는? int int xf( ) void f( ) void f( )int x int f( ) f f f f f f f f f f Fluent Interface프로그래밍 언어 함수 합성(Composition)수학 결합 법칙을 만족시킨다. (2 + 3) + 5 = 2 + (3 + 5) 연산 순서를 따로 지정하지 않아도 모호함 없이 수식의 값이 결정된다.
  • 24. The builder pattern is an object creation software design pattern. Instead of using numerous constructors, the builder pattern uses another object, a builder, that receives each initialization parameter step by step and then returns the resulting constructed object at once. https://en.wikipedia.org/wiki/Builder_pattern
  • 25. ?
  • 26. https://en.wikipedia.org/wiki/Fluent_interface a fluent interface (as first coined by Eric Evans and Martin Fowler) is an implementation of an object oriented API that aims to provide more readable code. Domain-Driven Design Refactoring A fluent interface is normally implemented by using method cascading (concretely method chaining) to relay the instruction context of a subsequent call. Self-Referential Ex.
  • 27. Vs. Vs. Builder Pattern Builder Pattern + Fluent Interface
  • 28. You are also a programmer! Can you understand this sentence? 글쓰기/읽기 글쓰기/읽기
  • 30. 조건도 함수다. 𝒇 𝒙 = 𝑥 + 1 𝑥 + 2 ( 𝒙 > 𝟎 ) ( 𝒙 < 𝟎 ) int output; if (x > 0) output = x + 1; else if (x < 0) output = x + 2; int output = if (x > 0) output = x + 1; else if (x < 0) output = x + 2; int output = if (x > 0) return x + 1; else if (x < 0) return x + 2; C R U D reate ead pdate elete ?
  • 31. 𝒇 𝒙 = 𝑥 + 1 𝑥 + 2 ( 𝑥 > 0 ) ( 𝑥 < 0 ) With 라이브러리, … https://github.com/wallymathieu/with 결과 값 조건
  • 33. flatMap map Reduce ByKey a b a b b a b a b b a b a b bkey 1 1 1 1 1value a bkey 2 3value 함수 합성 Fluent Interface 일급 시민 First-class citizen