SlideShare a Scribd company logo
Python으로 FP하기
Functional programming
Wonho Ha aka Las
하원호
프로그래머
AI에 관심이 많다.
Content
Hello Functional World
Python fallin into FP
더 FP적인 코드
더 좋은 코드를 향해서
Hello Functional World!
Introduction
Wonho Ha aka Las
들어가며
Functional Programming
들어가며
Functional
들어가며
Programming
FP의 장점
⬥명료함
⬥효율성
⬥테스트유용성
⬥병렬처리
⬥재미!
FP란
functional programming is a programming paradigm that treats
computation as the evaluation of mathematical functions and avoids
changing-state and mutable data.
FP란
Functional Programming
FP의 핵심
FP의 핵심
함수
FP의 핵심
고등학교 때의 기억을
되살려보자
함수
FP의 핵심
X가 같으면
Y도 같다
FP의 핵심
input이 같으면
output도 같다
FP의 핵심
Pure Function
(순수함수)
pure function is a function that has the following properties:
Its return value depends only on its parameters and not on any internal or external state
(such as local static variables, non-local variables or inputs from I/O devices).
Its evaluation has no side effect (such as mutation of local static variables or non-local
variables, or performing I/O operations).
Pure function
Pure function
그러나 우리의 함수가
순수할까요?
Pure function
Pure function
What’s matter
Side Effect
Pure function
Side Effect
비교해보자!
OOP vs FP
function
Method != Function
들어가며
FP를 알게된 계기
이미 사용중인 FP기법들
⬥Java8 Lambda, Stream
⬥Map/Reduce
⬥C++ tail recursion optimization
⬥JavaScript anonymous function
알게 된 계기
많은 함수형 언어들
⬥Rust
⬥Lisp(Clojure)
⬥Elixir
⬥Haskell
⬥Scala
알게 된 계기
들어가며
알게 된 계기
자연스럽게 관심을 갖게됨
알게 된 계기
Python에서도 FP를 해보자!
알게 된 계기
(사실 거의 습관처럼 사용해요)
Python fallin’ into FP
Python’s FP function
Wonho Ha aka Las
FP 적용기
Python은 multi-paradigm언어!
Python의 함수형 기능
⬥Map/Reduce
⬥High order function
⬥Lambda
⬥Generator
⬥Iterator
Python의 기능들
Python의 기능들
Higher Order Function
Higher Order Function
Higher Order Function
Higher Order Function
Higher Order Function
Python의 기능들
구현을 미룬다
Higher Order Function
Closure
Higher Order Function
함수가 저장하는 데이터
Higher Order Function
Higher Order Function
Python에서 FP를 할 때의 문제점
⬥tail optimization
⬥Lambda의 불편함
⬥immutable
⬥Curring
부딪히는 문제점
Python에서 FP를 할 때의 문제점
⬥tail optimization
⬥Lambda의 불편함
⬥immutable
⬥Curring
부딪히는 문제점
부딪히는 문제점
최적화가 되어있지 않다!
부딪히는 문제점
부딪히는 문제점
python is not
pure functional
부딪히는 문제점
해결책은?
구세주!
Decorator
(syntactic sugar)
더 FP적인 코드
Math + Lib
Wonho Ha aka Las
FP 적용기
지원하는 기능 < FP적인 코드
- Functional하게 문제를 해결하는 순서
1. 문제를 쪼갠다
2. 쪼개진 문제를 더 쪼갠다
3. 하나의 문제를 해결하는 순수함수를 만든다
4. 순수함수를 결합한다
FP적인 접근법
FP적인 접근법
OOP vs FP
FP적인 접근법
문제를 쪼개고 모듈화 한다.
Math
FP는 수학에 기반은 두고있다
Math
Category theory
Math
몇가지 공부할 수 있는 자료
Math
이론도 알았고 실제로 적용해볼까?
다 만들기는 불가능하기에
FP를 도와주는 라이브러리!
Python의 FP를 도와주는 Lib
⬥Pymonad
⬥fn.py
라이브러리
더 좋은 코드를 향해서
내가 하는 짓이 맞는걸까?
Wonho Ha aka Las
for문을 없애야 할까?
For loop is functional
Python Code
Pythonic Code
FP의 또다른 문제점
⬥속도
⬥can’t functional
⬥lots learning
여전히 존재하는 문제점들
One
Slow
One
Lazy Evaluation
One
Memoization
Two
Can’t Pure functional
Two
“IO monad doesn’t make a function pure;
it just makes it obvious it’s impure”
Three
Learning Time
그래서 결국은
적재적소에 사용하자
그래서 결국은
Q/A

More Related Content

Featured

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 

Featured (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Pycon2018 Functional Programming