{"action":"reopened","issue":{"url":"https://api.github.com/repos/android/android-ktx/issues/166","repository_url":"https://api.github.com/repos/android/android-ktx","labels_url":"https://api.github.com/repos/android/android-ktx/issues/166/labels{/name}","comments_url":"https://api.github.com/repos/android/android-ktx/issues/166/comments","events_url":"https://api.github.com/repos/android/android-ktx/issues/166/events","html_url":"https://github.com/android/android-ktx/issues/166","id":294604438,"number":166,"title":"Intent builder and helper methods","user":{"login":"gildor","id":186017,"avatar_url":"https://avatars3.githubusercontent.com/u/186017?v=4","gravatar_id":"","url":"https://api.github.com/users/gildor","html_url":"https://github.com/gildor","followers_url":"https://api.github.com/users/gildor/followers","following_url":"https://api.github.com/users/gildor/following{/other_user}","gists_url":"https://api.github.com/users/gildor/gists{/gist_id}","starred_url":"https://api.github.com/users/gildor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gildor/subscriptions","organizations_url":"https://api.github.com/users/gildor/orgs","repos_url":"https://api.github.com/users/gildor/repos","events_url":"https://api.github.com/users/gildor/events{/privacy}","received_events_url":"https://api.github.com/users/gildor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-02-06T01:47:53Z","updated_at":"2018-02-06T01:49:09Z","closed_at":null,"author_association":"NONE","body":"Kotlin uses lambda to build different types of complex objects:\r\n[buildString](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/build-string.html)\r\n[buildSequence](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines.experimental/build-sequence.html)\r\n[List builder](https://github.com/JetBrains/kotlin/blob/1.2.20/libraries/stdlib/src/kotlin/collections/Collections.kt#L152)\r\n\r\nI propose to add intent builder to ktx. That will work like:\r\n\r\n```kotlin\r\nbuildIntent {\r\n   action = \"some.Action\"\r\n   data = \"http://example.com\".toUri()\r\n   putExtra(\"name\", value)\r\n}\r\n```\r\n\r\nPossible implementation:\r\n\r\n```kotlin\r\ninline fun buildIntent(initializer: Intent.() -> Unit) = Intent().apply { initializer() }\r\n```\r\n\r\nAlso we can move often used properties to arguments of the function, such as action:\r\n```kotlin\r\ninline fun buildIntent(action: String) = Intent(action).apply { initializer() }\r\n```\r\nbut not sure that this is make a lot of sense.\r\n\r\nBut another feature would more useful. Reified activity intent builder:\r\n```kotlin\r\ninline fun <reified T> buildIntent(\r\n        context: Context, \r\n        initializer: Intent.() -> Unit\r\n) = Intent(context, T::class.java).apply { initializer() }\r\n```\r\n\r\nThis version also can provide empty lambda as default argument for initilizer, to make builder usage optional, reified acitivity creation already useful feature\r\n\r\nPossible naming:\r\n\r\n`Intent` (same as `List` builder, that looks like constructor call but actually function)\r\n`buildIntent` (same as `stringBuilder`)\r\n`intent` is short but doesn't follow current Kotlin naming and clashes with variable names"}}
{"actor":{"display_login":"JakeWharton"}}