{"action":"created","issue":{"url":"https://api.github.com/repos/ReactiveX/RxJava/issues/3154","labels_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/3154/labels{/name}","comments_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/3154/comments","events_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/3154/events","html_url":"https://github.com/ReactiveX/RxJava/pull/3154","id":100904709,"number":3154,"title":"Add Observable.lazy() as a companion for Observable.defer()","user":{"login":"artem-zinnatullin","id":967132,"avatar_url":"https://avatars.githubusercontent.com/u/967132?v=3","gravatar_id":"","url":"https://api.github.com/users/artem-zinnatullin","html_url":"https://github.com/artem-zinnatullin","followers_url":"https://api.github.com/users/artem-zinnatullin/followers","following_url":"https://api.github.com/users/artem-zinnatullin/following{/other_user}","gists_url":"https://api.github.com/users/artem-zinnatullin/gists{/gist_id}","starred_url":"https://api.github.com/users/artem-zinnatullin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artem-zinnatullin/subscriptions","organizations_url":"https://api.github.com/users/artem-zinnatullin/orgs","repos_url":"https://api.github.com/users/artem-zinnatullin/repos","events_url":"https://api.github.com/users/artem-zinnatullin/events{/privacy}","received_events_url":"https://api.github.com/users/artem-zinnatullin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ReactiveX/RxJava/labels/Enhancement","name":"Enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":21,"created_at":"2015-08-14T01:03:47Z","updated_at":"2015-08-21T08:57:40Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ReactiveX/RxJava/pulls/3154","html_url":"https://github.com/ReactiveX/RxJava/pull/3154","diff_url":"https://github.com/ReactiveX/RxJava/pull/3154.diff","patch_url":"https://github.com/ReactiveX/RxJava/pull/3154.patch"},"body":"Yep, this is a new operator.\r\n\r\nMotivation? `Observable.defer()` requires function that returns `Observable<T>` when usually we don't want to create `Observable<T>` manually, we just want to defer execution of some function.\r\n\r\nLike this:\r\n\r\n```java\r\nObservable\r\n  .lazy(() -> someFunc())\r\n  .subscribeOn(...)\r\n  ...\r\n```\r\n\r\nInstead of this:\r\n\r\n```java\r\nObservable\r\n  .defer(() -> Observable.just(someFunc()))\r\n  .subscribeOn(...)\r\n  ...\r\n```\r\n\r\nAnd more important case:\r\n```java\r\nObservable\r\n  .lazy(() -> {\r\n    Value value = ...;\r\n    // some code\r\n    return value;\r\n  })\r\n .subscribeOn(...)\r\n ...\r\n```\r\n\r\nInstead of this:\r\n\r\n```java\r\nObservable\r\n  .defer(() -> {\r\n    Value value = ...;\r\n    // some code\r\n    return Observable.just(value);\r\n  })\r\n .subscribeOn(...)\r\n ...\r\n```\r\n\r\nI'd use name `defer` but both methods will have same type erasure (`Func0<Observable>` and `Func0<T>`), so I had to use a different name.\r\n\r\nQuestions:\r\n\r\n1. Useful or not? For me — deferring some function call is a common task.\r\n2. Naming.\r\n\r\nIf the decision about this operator will be positive — I'll add javadoc to this PR and then create separate PR for `Single.lazy()`.\r\n"},"comment":{"url":"https://api.github.com/repos/ReactiveX/RxJava/issues/comments/133339293","html_url":"https://github.com/ReactiveX/RxJava/pull/3154#issuecomment-133339293","issue_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/3154","id":133339293,"user":{"login":"dimsuz","id":42920,"avatar_url":"https://avatars.githubusercontent.com/u/42920?v=3","gravatar_id":"","url":"https://api.github.com/users/dimsuz","html_url":"https://github.com/dimsuz","followers_url":"https://api.github.com/users/dimsuz/followers","following_url":"https://api.github.com/users/dimsuz/following{/other_user}","gists_url":"https://api.github.com/users/dimsuz/gists{/gist_id}","starred_url":"https://api.github.com/users/dimsuz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimsuz/subscriptions","organizations_url":"https://api.github.com/users/dimsuz/orgs","repos_url":"https://api.github.com/users/dimsuz/repos","events_url":"https://api.github.com/users/dimsuz/events{/privacy}","received_events_url":"https://api.github.com/users/dimsuz/received_events","type":"User","site_admin":false},"created_at":"2015-08-21T08:57:40Z","updated_at":"2015-08-21T08:57:40Z","body":"`deferSingle` sounds nice to me.\r\nAlso thought of `deferValue`."}}