HyunWoo Lee
May 12, 2023
200

Functional Kotlin makes Kotlin functional

KotlinConf 2023 Global in Songdo에서 발표한 코틀린 함수형 프로그래밍 발표 자료입니다.

May 12, 2023

Transcript

1. @l2hyunwoo KotlinConf’23 Global in Songdo Mathpresso Inc. Android/React Native Developer

Functional Kotlin Makes Kotlin functional HyunWoo Lee
2. ೣࣻഋ ೐۽Ӓې߁җ য়೧ Lambda Algebra Monoid Functor / Applicative Functor

Tail recursion Currying
3. ೣࣻഋ ೐۽Ӓې߁җ য়೧ Lambda Algebra Monoid Functor / Applicative Functor

Tail recursion Currying ੿݈ ੉ѱ पઁ ѐߊী ੄޷о ੓ਸөਃ?
4. ೣࣻഋ ೐۽Ӓې߁ ੽Ӕ ݾ੸ਸ ੉೧ೞҊ যڌѱ ࢎਊ೧ঠೡ ૑ ঌইঠ ೞݴ

Ӓ ੉റী ޖ঺੉ ੓ח ૑ ౵ঈ೧ب ן૑ ঋ׮
5. Why we should use it? ೣࣻഋ ೐۽Ӓې߁ਸ ഝਊೞݶ ௏٘ܳ рѾೞѱ

੘ࢿೡ ࣻ ੓Ҋ ӝמ੄ ഛ੢੉ ए਋ݴ ࠁ׮ উ੹ೠ ௏٘ܳ ੘ࢿೡ ࣻ ੓׮

Scopeਵ۽ Ѻܻೠ׮
13. ਫ਼Ӭ! ੉Ѣ ೣࣻഋ ೐۽Ӓې߁੉ ݏաਃ? Functional Programming is sometimes treated

as synonymous with Purely functional programming. When a pure function is called with some given arguments, it will always return the same result, and cannot be affected by any mutable state or other side effect. - Hudak, Paul (Conception, evolution and application of functional programming lauguages)

( 2, 5 )

( 2, 5 ) 7
17. function sum(x: int, y: int) ( 2, 5 ) 7

ੑ۱੉ زੌೞݶ Ѿҗо ೦࢚ э਷ ೣࣻܳ ࣽࣻ ೣࣻ ( Pure Function) ۄ ೠ׮ Pure Function and Side Effect

( 2, 5 ) 1st
20. Pure Function and Side Effect function sumWithSideEffect(x: int, y: int)

( 2, 5 ) 7 1st

( 3, 6 ) 2nd
22. Pure Function and Side Effect function sumWithSideEffect(x: int, y: int)

( 3, 6 ) 2nd 16
23. Pure Function and Side Effect function sumWithSideEffect(x: int, y: int)

( 3, 6 ) 2nd 16

25. Pure Function and Side Effect ೣࣻ ղীࢲ ҙ੢ೞ૑ ঋח, ੹৉

࢚క/߸ࣻ ഑਷ (౵ੌ, ചݶ) ੑ୹۱١ਸ ನೣೠ ৻ࠗ ࢚కী ৔ೱਸ ઴ ࣻ ੓Ҋ ੉ܳ ҙ଴ೞח ೯ਤܳ ನೣೞח ೣࣻܳ Side Effectۄ ೠ׮.
26. Pure Function and Side Effect ೣࣻഋ ೐۽Ӓې߁ਸ ഝਊೞݶ ௏٘ܳ рѾೞѱ

੘ࢿೡ ࣻ ੓Ҋ ӝמ੄ ഛ੢੉ ए਋ݴ ࠁ׮ উ੹ೠ ௏٘ܳ ੘ࢿೡ ࣻ ੓׮
27. Pure Function and Side Effect ࣽࣻೣࣻܳ ࢎਊೞݶ زੌೠ Ѿҗܳ ৘ஏೡ

ࣻ ੓ਵ޲۽ (ଵઑ ైݺࢿ) ೣࣻ Ӓ ੗୓ܳ ݽٕചػ ӝמਵ۽ ࢎਊೡ ࣻ ੓׮. ژೠ ৻ࠗ о߸ ࢚కܳ ߸҃ೞ૑ ঋਵ޲۽ زदࢿ ೐۽Ӓې߁ীࢲ ҕਬ ੗ਗ ߸҃ী ؀ೠ ҙबࢎܳ ઁೡ ࣻ ੓׮. ੉۠ ੉੼ਵ۽ ೣࣻഋ ೐۽Ӓې߁ীࢲח ࣽࣻ ೣࣻ੄ ࢎਊਸ ૑ೱೠ׮.

೐۽Ӓې߁ ߑधੌө?

ઁ؀۽ ٜ݅ ࣻ হ׮
30. Aspect of Functional Programming ৻ࠗ ࣁ҅ܳ ߸҃ਸ दெঠ ೞա ߸҃ਸ

दఃח ࠗ࠙ਸ ୭ࣗചೞҊ ҳ࠙(Ѻܻ)दః੗

Scopeਵ۽ Ѻܻೠ׮

33. Ҋରೣࣻܳ ഝਊೠ ӝמ ഛ੢ CSVо ইצ ׮ܲ ౵ੌ ഋध ഑਷

Plain Text۽ Append ೞח ӝמ੉ ୶оػ׮ݶ?
34. Ҋରೣࣻܳ ഝਊೠ ӝמ ഛ੢ ё୓ܳ Stringਵ۽ ੹ജೞח ۽૒ਸ ৻ࠗীࢲ ઱ੑदெ

ҕా ۽૒ী ׮ഋࢿਸ ઁҕ
35. ઺р ੼Ѩ ਸ ੉೧ೞҊ ࢎਊ೧ঠೡ ૑ ঌইঠ ೞݴ Ӓ ੉റী

ޖ঺੉ ੓ח ૑ ౵ঈ೧ب ן૑ ঋ׮ ݾ੸ যڌѱ
36. ઺р ੼Ѩ → উ੿ࢿ, ਬ૑ࠁࣻࢿ, оةࢿ ૐо → ࣽࣻೣࣻ ഝਊ,

Side Effect Ѻܻ ݾ੸ যڌѱ
37. More, Functional Programming Ҋରೣࣻܳ ഝਊೞৈ ੤ࢎਊࢿਸ ՑযৢܻҊ ࠁ׮ ؊ উ੿੸ਵ۽

೐۽Ӓې߁ਸ ೞҊ र׮ݶ?
38. More, Functional Programming Ҋରೣࣻܳ ഝਊೞৈ ੤ࢎਊࢿਸ ՑযৢܻҊ ࠁ׮ ؊ উ੿੸ਵ۽

೐۽Ӓې߁ਸ ೞҊ र׮ݶ? Ҋରೣࣻܳ ഝਊೞח ё୓(ё୓ ஶప੉ց)੄ ౠࢿਸ ঌҊ, ੉ܳ ഝਊೞݶ ػ׮
39. Category Theory Ҋରೣࣻܳ ഝਊೞৈ ࢜۽਍ ఋੑ/ӝמਸ ઁҕೞӝ ਤ೧ࢶ ੉ܳ ҳࢿೞח

ఋੑী ؀೧ ঌইঠ ೠ׮.

43. Category Theory ߧ઱ۿ ( Category Theory)ীࢲח ҳઑ୓ ( Object)৬ ҳઑ୓ٜр੄

ҙ҅ ( Morphism, ࢎ࢚)ܳ ׮ܘ׮

ೣࣻ

ҡଳ׮ ੿ب੄ ੄޷)

57. Monad ਽ਊ: ৈ۞ ா੉झܳ ೠ ଃਵ۽ ী۞ ߊࢤ द ী۞

ఋੑਸ Monad ఋੑਵ۽ ೠߣ ؊ хऱળ׮ݶ?

࢚ҙহ੉ ѐߊ੗о ۽૒ਸ ୓੉׬೧ب ޙઁо হب۾ ୊ܻ ೡ ࣻ ੓׮