Guest User

Untitled

a guest
Mar 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. class CatFragment: Fragment() {
  2. companion object {
  3. fun newInstance(catId: String) = CatFragment().withArgs {
  4. putString("catId", catId)
  5. }
  6. }
  7. }
  8. class DogFragment: Fragment() {
  9. companion object {
  10. fun newInstance(dogId: String) = DogFragment().withArgs {
  11. putString("dogId", dogId)
  12. }
  13. }
  14. }
  15.  
  16. inline fun <T: Fragment> T.withArgs(
  17. argsBuilder: Bundle.() -> Unit): T =
  18. this.apply {
  19. arguments = Bundle().apply(argsBuilder)
  20. }
  21.  
  22. // if(something != null && something.thingy) {
  23. // ...
  24. // } else {
  25. // ...
  26. // }
  27.  
  28. something?.takeIf { it.thingy }?.let {
  29. ...
  30. } ?: {
  31. ...
  32. }
Add Comment
Please, Sign In to add comment