KotlinConf 2023 Global in Songdo에서 발표한 코틀린 함수형 프로그래밍 발표 자료입니다.
@l2hyunwooKotlinConf’23 Global in SongdoMathpresso Inc. Android/React Native DeveloperFunctional KotlinMakesKotlin functionalHyunWoo Lee
View Slide
ೣࣻഋ ۽Ӓې߁җ য়೧Lambda Algebra MonoidFunctor / Applicative Functor Tail recursionCurrying
ೣࣻഋ ۽Ӓې߁җ য়೧Lambda Algebra MonoidFunctor / Applicative Functor Tail recursionCurrying݈ ѱ पઁ ѐߊী о ਸөਃ?
ೣࣻഋ ۽Ӓې߁ Ӕݾਸ ೧ೞҊযڌѱ ࢎਊ೧ঠೡ ঌইঠ ೞݴӒ റী ޖ ח ঈ೧ب ן ঋ
Why we should use it?ೣࣻഋ ۽Ӓې߁ਸ ഝਊೞݶ٘ܳ рѾೞѱ ࢿೡ ࣻ Ҋ ӝמ ഛ एݴࠁ উೠ ٘ܳ ࢿೡ ࣻ
рѾೠ ٘ ࢿೞӝ
߸زਸ ݶࢲ উࢿ ֫ӝ
߸زਸ ݶࢲ উࢿ ֫ӝё/৻ࠗ ࢚క߸ز ח ࠗ࠙࠶۾ Scopeਵ۽Ѻܻೠ
ਫ਼Ӭ! Ѣ ೣࣻഋ ۽Ӓې߁ ݏաਃ?Functional Programming is sometimes treated as synonymous withPurely 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)
Pure Function and Side Effectfunction sum(x: int, y: int)
Pure Function and Side Effectfunction sum(x: int, y: int)(2, 5)
Pure Function and Side Effectfunction sum(x: int, y: int)(2, 5)7
function sum(x: int, y: int)(2, 5)7ੑ۱ زੌೞݶѾҗо ೦࢚ э ೣࣻܳࣽࣻ ೣࣻ(Pure Function)ۄ ೠPure Function and Side Effect
Pure Function and Side Effectfunction sumWithSideEffect(x: int, y: int)
Pure Function and Side Effectfunction sumWithSideEffect(x: int, y: int)(2, 5)1st
Pure Function and Side Effectfunction sumWithSideEffect(x: int, y: int)(2, 5)71st
Pure Function and Side Effectfunction sumWithSideEffect(x: int, y: int)(3, 6)2nd
Pure Function and Side Effectfunction sumWithSideEffect(x: int, y: int)(3, 6)2nd16
Pure Function and Side Effect
Pure Function and Side Effectೣࣻ ղীࢲ ҙೞ ঋח, ࢚క/߸ࣻ (ੌ, ചݶ) ੑ۱١ਸ ನೣೠ৻ࠗ ࢚కী ೱਸ ࣻ Ҋ ܳ ҙೞח ೯ਤܳ ನೣೞח ೣࣻܳSide Effectۄ ೠ.
Pure Function and Side Effectೣࣻഋ ۽Ӓې߁ਸ ഝਊೞݶ٘ܳ рѾೞѱ ࢿೡ ࣻ Ҋ ӝמ ഛ एݴࠁ উೠ ٘ܳ ࢿೡ ࣻ
Pure Function and Side Effectࣽࣻೣࣻܳ ࢎਊೞݶ زੌೠ Ѿҗܳ ஏೡ ࣻ ਵ۽ (ଵઑ ైݺࢿ)ೣࣻ Ӓ ܳ ݽٕചػ ӝמਵ۽ ࢎਊೡ ࣻ .ژೠ ৻ࠗ о߸ ࢚కܳ ߸҃ೞ ঋਵ۽زदࢿ ۽Ӓې߁ীࢲ ҕਬ ਗ ߸҃ী ೠ ҙबࢎܳ ઁೡ ࣻ .۠ ਵ۽ ೣࣻഋ ۽Ӓې߁ীࢲח ࣽࣻ ೣࣻ ࢎਊਸ ೱೠ.
Aspect of Functional ProgrammingӒ۞ݶ ࣽࣻ ೣࣻ݅ਸ ࢎਊೞח Ѫೣࣻഋ ۽Ӓې߁ ߑधੌө?
Aspect of Functional ProgrammingӒۧӝח ೞա,ӒېоҌ рױೠ ӝמ ೞաઑରઁ۽ ٜ݅ ࣻ হ
Aspect of Functional Programming৻ࠗ ࣁ҅ܳ ߸҃ਸ दெঠ ೞա߸҃ਸ दఃח ࠗ࠙ਸ ୭ࣗചೞҊ ҳ࠙(Ѻܻ)दః
Ҋରೣࣻܳ ഝਊೠ ӝמ ഛ
Ҋରೣࣻܳ ഝਊೠ ӝמ ഛCSVо ইצ ܲ ੌ ഋध Plain Text۽ Appendೞח ӝמ ୶оػݶ?
Ҋରೣࣻܳ ഝਊೠ ӝמ ഛёܳ Stringਵ۽ ജೞח ۽ਸ৻ࠗীࢲ ੑदெҕా ۽ী ഋࢿਸ ઁҕ
р Ѩਸ ೧ೞҊࢎਊ೧ঠೡ ঌইঠ ೞݴӒ റী ޖ ח ঈ೧ب ן ঋݾযڌѱ
р Ѩ→ উࢿ, ਬࠁࣻࢿ, оةࢿ ૐо→ ࣽࣻೣࣻ ഝਊ, Side Effect Ѻܻݾযڌѱ
More, Functional ProgrammingҊରೣࣻܳ ഝਊೞৈ ࢎਊࢿਸ ՑযৢܻҊࠁ ؊ উਵ۽ ۽Ӓې߁ਸ ೞҊ रݶ?
More, Functional ProgrammingҊରೣࣻܳ ഝਊೞৈ ࢎਊࢿਸ ՑযৢܻҊࠁ ؊ উਵ۽ ۽Ӓې߁ਸ ೞҊ रݶ?Ҋରೣࣻܳ ഝਊೞח ё(ё ஶపց)ౠࢿਸ ঌҊ, ܳ ഝਊೞݶ ػ
Category TheoryҊରೣࣻܳ ഝਊೞৈ ࢜۽ ఋੑ/ӝמਸ ઁҕೞӝ ਤ೧ࢶܳ ҳࢿೞח ఋੑী ೧ ঌইঠ ೠ.
ೣࣻഋী ೠ “ஶపց"Monad
ೣࣻഋী ೠ “ஶపց"Monadח ূبಔఠ పҊܻ ݽ֢٘Monad
Category Theoryߧۿ(Category Theory)ীࢲח ҳઑ(Object)৬ҳઑٜр ҙ҅(Morphism, ࢎ࢚)ܳ ܘ
Functorف పҊܻ р ೣࣻҊҳઑח ҳઑ۽, ೣࣻח ೣࣻ۽ दఃח ೣࣻ
Functor۞ݶ য٣ࢲ ݆ࠄ Ѫ э ঋաਃ?
Functor
Functor ޙઁ
Monoidਤ ࢿਸ ݅ೞח పҊܻ
Monoidਤ ࢿਸ ݅ೞח పҊܻ(ো যו ੌࠗ࠙ਸ ݢ ࣻ೯ೞ؊ۄب ҡଳ ب )
Monad
Monad ࢿਸ ഝਊೞৈ ػ ఋੑਸ ߩӡ ࣻ
MonadflatMap ೣࣻܳ ࢤп೧ࠁ!
MonadNested Optional۽ оٙସ؍ ٘ب
Monad ਊ: ৈ۞ ாझܳ ೠ ଃਵ۽
Monad ਊ: ৈ۞ ாझܳ ೠ ଃਵ۽ী۞ ߊࢤ द ী۞ ఋੑਸ Monad ఋੑਵ۽ ೠߣ ؊ хऱળݶ?
Monadܳ ഝਊೠ ࢚క ܻ Monad ղࠗ ࢚కܳ ইח Ѫҗ ࢚ҙহѐߊо ۽ਸ ೧ب ޙઁо হب۾ ܻೡ ࣻ
Monad is EverywhereSpring Reactor(Mono)
Monad is EverywhereRxJava (Kotlin)
Monad is Everywhere
Monad is EverywhereKotlin Result
Monad is EverywhereCompose Modifier
Thanks!@l2hyunwooKotlinConf’23 Global in SongdoMathpresso Inc. Android/React Native DeveloperSlido