Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. val accountId = run {
  2.     val accountId = getIt()
  3.     doSomethingWithIt(accountId)
  4.     accountId // returns it from this block
  5. }
  6.  
  7. // vs.
  8.  
  9. val accountId = run {
  10.     getIt().also { accountId ->
  11.         doSomethingWithIt(accountId)
  12.     }
  13. }
  14.  
  15. // alternative to #1
  16.  
  17. val accountId = run foo@{
  18.     val accountId = getIt()
  19.     doSomethingWithIt(accountId)
  20.     return@foo accountId // returns it from this block named foo
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement