개발 팁
[kotlin] scope functions(run, let, with, apply, also)
북치던노인
2024. 7. 17. 14:43
Function | Object reference | Return value | Is extension function |
let | it | Lambda result | Yes |
run | this | Lambda result | Yes |
run | - | Lambda result | No: called without the context object |
with | this | Lambda result | No: takes the context object as an argument. |
apply | this | Context object | Yes |
also | it | Context object | Yes |
다른 블로그 봤는데 이해가 안돼서 정리할려고 티스토리 켜고 공식문서 펼쳐봤는데
공식문서 설명이 젤 쉽네.. 심지어 영어인데, 그냥 저 표로 끝!
https://kotlinlang.org/docs/scope-functions.html#function-selection
takeIf, takeUnless 도 잘 써먹자!