Created
July 18, 2018 09:09
-
-
Save sajjadyousefnia/6ca462ef321b8c2383db10d88fa525cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val original = "abc" | |
// مقدار دچار تغییر میشه و به قسمت بعدی زنجیره منتقل میشه | |
original.let { | |
println("The original String is $it") // "abc" | |
it.reversed() // دچار تغییر میشه و به عنوان پارامتر به قسمت بعدی زنجیره فرستاده میشه | |
}.let { | |
println("The reverse String is $it") // "cba" | |
it.length // همونطور که میبینید میتونه به نوع دیگری تبدیل بشه | |
}.let { | |
println("The length of the String is $it") // 3 | |
} | |
// روش نادرست استفاده از این حلقه | |
// توی هر قسمت از زنجیره از یک مقدار یکسان استفاده میشه | |
original.also { | |
println("The original String is $it") // "abc" | |
it.reversed() // حتی اگه دچار تغیر بشه نمیشه اون رو توی قسمت بعدی زنجیره استفاده کرد | |
}.also { | |
println("The reverse String is ${it}") // "abc" | |
it.length // حتی اگه دچار تغیر بشه نمیشه اون رو توی قسمت بعدی زنجیره استفاده کرد}.also { | |
println("The length of the String is ${it}") // "abc" | |
} | |
// روش درست جایگزین قبلی | |
original.also { | |
println("The original String is $it") // "abc" | |
}.also { | |
println("The reverse String is ${it.reversed()}") // "cba" | |
}.also { | |
println("The length of the String is ${it.length}") // 3 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment