์ถ์ฒ
https://kotlintutorial.io/local-functions-in-kotlin/
Local functions in Kotlin
In Kotlin there are local functions that can be defined within a larger function. These functions are only visible within this larger function and cannot be accessed from outside. Local functions have the advantage of making code more readable and clear by
kotlintutorial.io
ChatGPT
https://cornswrold.tistory.com/464
[Kotlin] ์ฝํ๋ฆฐ ๋ก์ปฌํจ์์ ํ์ฅ
์ฝํ๋ฆฐ์์๋ ํจ์์์ ์ถ์ถํ ํจ์๋ฅผ ์ ํจ์ ๋ด๋ถ์ ์ค์ฒฉ์ํฌ ์ ์๋ค. ๊ทธ๋ ๊ฒ ํ๋ฉด ๋ฌธ๋ฒ์ ์ธ ๋ถ๊ฐ ๋น์ฉ์ ๋ค์ด์ง ์๊ณ ๊น๋ํ๊ฒ ์ฝ๋๋ฅผ ์กฐ์งํ ์ ์๋ค. (DRY. Don't Repeat Yourself) ํํ ๋ฐ์ํ๋
cornswrold.tistory.com
https://realkotlin.com/tutorials/2018-06-12-local-functions-in-kotlin/
Local functions in Kotlin
Kotlin supports local functions, i.e. it allows you to put a function inside a function.
realkotlin.com
๋ก์ปฌ ํจ์ Local Functions
ํจ์ ์์ ์ ์๋ ํจ์. ์ธ๋ถ ํจ์ ์์์๋ง ๋ณผ ์ ์๊ณ , ๊ทธ ์ธ๋ถ์์๋ ์ ๊ทผ์ด ๋ถ๊ฐ๋ฅํ๋ค.
๋ก์ปฌ ํจ์์ ๋ชฉ์
1. ๋ก์ง ์บก์ํ
๋ก์ปฌ ํจ์๋ ์ธ๋ถ ํจ์ ์์์ ์ ์ ์๋๊ณ ํนํํ ์์ ์ ์ํํจ์ผ๋ก์จ ๋ก์ง์ ์บก์ํํ๋ค.
2. ๊ฐ๋ ์ฑ
ํน์ ๋ชฉ์ ๋ฌ์ฑ์ ์ํด ๋ช ํํ๊ฒ ์ ์๋ ๋ก์ปฌ ํจ์๋ฅผ ๋ง๋ค์ด ์ฝ๋ ๊ฐ๋ ์ฑ์ด ํฅ์๋๋ค.
3. ์ฌ์ฌ์ฉ์ฑ
์ฝ๋ ์ค๋ณต ์์ด ์ธ๋ถ ํจ์ ์์์ ์ฌ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค. ์ค๋ฅ ์์ค๋ฅผ ์ค์ด๊ณ ๋ ์ผ๊ด๋๊ณ ์ ์ง๋ณด์ ๊ฐ๋ฅํ ์ฝ๋๋ฅผ ๋ง๋ ๋ค.
4. ํจ์ ์ฃผ์์ ์ปจํ ์ค์ ์ ๊ทผ
๋ก์ปฌ ํจ์๋ ์ธ๋ถ ํจ์์ ๋งค๊ฐ๋ณ์์ ๋ณ์์ ์ ๊ทผํ ์ ์๋ค. ์ด๋ฅผ ํตํด ๋ก์ปฌ ํจ์์ ์ปจํ ์คํธ ๊ฐ์ ์ํธ์์ฉ์ด ๊ฐ๋ฅํด์ ๋ก์ปฌ ํจ์์ ์ถ๊ฐ ๋งค๊ฐ๋ณ์๋ฅผ ์ ๋ฌํ์ง ์์๋ ๋๋ค.
๋ก์ปฌ ํจ์๋ ๋ฉ์๋ ์ถ์ถ ๋ฆฌํฉํ ๋ง์์๋ณด๋ค ๋ ํจ์จ์ ์ผ๋ก ์ฝ๋๋ฅผ ๊ด๋ฆฌํ๊ณ ๋ถํ์ํ ์ค๋ณต์ ๋ฐฉ์งํ ์ ์๋ค.
๋ฉ์๋ ์ถ์ถ ๋ฆฌํฉํ ๋ง์์ ์ข ์ข ๋ฐ์ํ๋ ๋ถํ์ํ ์ฝ๋๋ฅผ ์ค์ผ ์ ์๋ ๋ฐฉ๋ฒ ์ค ํ๋๊ฐ ๋ก์ปฌ ํจ์์ ์ฌ์ฉ์ด๋ค.
๋ฉ์๋ ์ถ์ถ ๋ฆฌํฉํ ๋ง์ ํตํด ์ฝ๋๋ฅผ ๋ ์์ ๋จ์๋ก ๋๋ ๋, ์ธ๋ถ ํด๋์ค๋ ๋ด๋ถ ํด๋์ค, ํ์ผ๋ก ํจ์๋ฅผ ๋ถ๋ฆฌํ๋ ๋์ ํด๋น ํจ์ ๋ด๋ถ์์๋ง ์ฌ์ฉ๋๋ ๋ก์ง์ด๋ผ๋ฉด ๋ก์ปฌ ํจ์๋ก ์ ์ํ ์ ์๋ค. ์ด๋ ๊ฒ ํ๋ฉด ์ฝ๋๊ฐ ๋ ๊น๋ํ๊ณ ๋ถํ์ํ๊ฒ ๋ง์ ๋ฉ์๋๋ฅผ ํด๋์ค๋ ํ์ผ์ ์ถ๊ฐํ ํ์๊ฐ ์๋ค.
์
https://cornswrold.tistory.com/464
[Kotlin] ์ฝํ๋ฆฐ ๋ก์ปฌํจ์์ ํ์ฅ
์ฝํ๋ฆฐ์์๋ ํจ์์์ ์ถ์ถํ ํจ์๋ฅผ ์ ํจ์ ๋ด๋ถ์ ์ค์ฒฉ์ํฌ ์ ์๋ค. ๊ทธ๋ ๊ฒ ํ๋ฉด ๋ฌธ๋ฒ์ ์ธ ๋ถ๊ฐ ๋น์ฉ์ ๋ค์ด์ง ์๊ณ ๊น๋ํ๊ฒ ์ฝ๋๋ฅผ ์กฐ์งํ ์ ์๋ค. (DRY. Don't Repeat Yourself) ํํ ๋ฐ์ํ๋
cornswrold.tistory.com
https://realkotlin.com/tutorials/2018-06-12-local-functions-in-kotlin/
Local functions in Kotlin
Kotlin supports local functions, i.e. it allows you to put a function inside a function.
realkotlin.com
'๋น ๊ตฌ๋ฉ ์ฑ์ฐ๊ธฐ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํจ์ํ ํ๋ก๊ทธ๋๋ฐ] ์ํ ๋ณํ eta conversion (1) | 2024.10.16 |
---|---|
[Java][Kotlin] ๊ฐ์์ฑ ๋ณ๊ฒฝ์ ์ฐจ์ด ๋น๊ต (0) | 2024.10.15 |
[ํ๋ก๊ทธ๋๋ฐ] ๋ฉ์๋ ์ถ์ถ ๋ฆฌํฉํ ๋ง Extract Method (0) | 2024.10.15 |
[Kotlin] Infix call ์ค์ ํธ์ถ (0) | 2024.10.14 |
[Kotlin] Soft Keyword, Hard Keyword, Modifier Keyword (1) | 2024.10.14 |