1 more readable 2 usually more overhead 3 we don t know
play

1. More readable 2. (Usually) More overhead 3. We dont know which - PowerPoint PPT Presentation

1. More readable 2. (Usually) More overhead 3. We dont know which one we aspire to more A clever title Christina Lee Two Stones, One Bird A clever title Christina Lee Kill two birds with one stone Kill two birds with one


  1. with / apply let / also

  2. public inline fun <T, R> T.let( block: (T) -> R ): R = block( this ) with / apply let / also

  3. Spoiler Alert: Everything but with() public inline fun <T, R> T.let( block: (T) -> R ): R = block( this ) with / apply let / also

  4. public inline fun <T, R> T.let( block: (T) -> R ): R = block( this ) with / apply let / also

  5. public inline fun <T, R> T.let( block: (T) -> R ): R = block( this ) with / apply 😲 let / also

  6. val usernameView: View? = user. name ?. let { name -> ViewWithText( context , name) } with / apply let / also

  7. with / apply let / also DexMethods.kt: http://bit.ly/2xFN3Bd

  8. 🎊 🎊 Nullablity with / apply let / also

  9. with / apply let / also

  10. with / apply let / also

  11. public inline fun <T> T.also( block: (T) -> Unit ): T { block( this ); with / apply return this }a let / also

  12. public inline fun <T> T.also( block: (T) -> Unit ): T { block( this ); with / apply return this }a let / also

  13. public inline fun <T> T.also( block: (T) -> Unit ): T { block( this ); with / apply return this }a let / also

  14. public inline fun <T> T.also( block: (T) -> Unit ): T { block( this ); with / apply return this }a let / also

  15. public inline fun <T> T.also( block: (T) -> Unit ): T { block( this ); Plain with / apply return this lambda }a let / also

  16. “Oh and also…” public inline fun <T> T.also( block: (T) -> Unit ): T { block( this ); with / apply return this }a let / also

  17. “Oh and also…” foo. bar () .also { } . baz () with / apply let / also

  18. ???

  19. Are you calling repeated functions on an object? Yes No Do you need to Do you need to return the object? return the object? Yes No Yes No Apply With Also Let

  20. need caller to be don’t need returned caller returned need receiver apply with don’t need receiver also let

  21. 1. Things return values you don’t always need to use 2. You can call non-receiver functions inside lambdas with receivers

  22. val idk = with (foo) { bar () baz () }

  23. val idk: Baz = with (foo) { bar () baz () }

  24. val idk: Baz = with (foo) { bar () createBaz () }

Recommend


More recommend