{"action":"created","comment":{"url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/pulls/comments/24719294","id":24719294,"diff_hunk":"@@ -527,13 +527,62 @@ public func concat<T, E>(next: SignalProducer<T, E>)(producer: SignalProducer<T,\n \treturn SignalProducer(values: [producer, next]) |> concat\n }\n \n+public func switchToLatest<T, E>(producer: SignalProducer<SignalProducer<T, E>, E>) -> SignalProducer<T, E> {\n+\treturn SignalProducer<T, E> { sink, disposable in\n+\t\tlet producerCompleted = Atomic(false)\n+\t\tlet latestCompleted = Atomic(false)\n+\t\t\n+\t\tlet completeIfNecessary: () -> () = {\n+\t\t\tif producerCompleted.value && latestCompleted.value {\n+\t\t\t\tsendCompleted(sink)\n+\t\t\t}\n+\t\t}\n+\n+\t\tlet latestDisposable = SerialDisposable()\n+\t\tdisposable.addDisposable(latestDisposable)\n+\n+\t\tproducer.startWithSignal { signal, producerDisposable in\n+\t\t\tdisposable.addDisposable(producerDisposable)\n+\t\t\t\n+\t\t\tsignal.observe(\n+\t\t\t\tnext: { signal in\n+\t\t\t\t\tlatestDisposable.innerDisposable = nil\n+\t\t\t\t\tlatestCompleted.value = false\n+\t\t\t\t\t\n+\t\t\t\t\tsignal.startWithSignal { signal, signalDisposable in\n+\t\t\t\t\t\tlatestDisposable.innerDisposable = signalDisposable\n+\t\t\t\t\t\t\n+\t\t\t\t\t\tmaterialize(signal).observe { event in","path":"ReactiveCocoa/Swift/SignalProducer.swift","position":29,"original_position":29,"commit_id":"bffd8cdff44fb9bb239ff4bd22e764f505d6c6a7","original_commit_id":"bffd8cdff44fb9bb239ff4bd22e764f505d6c6a7","user":{"login":"brow","id":238331,"avatar_url":"https://avatars.githubusercontent.com/u/238331?v=3","gravatar_id":"","url":"https://api.github.com/users/brow","html_url":"https://github.com/brow","followers_url":"https://api.github.com/users/brow/followers","following_url":"https://api.github.com/users/brow/following{/other_user}","gists_url":"https://api.github.com/users/brow/gists{/gist_id}","starred_url":"https://api.github.com/users/brow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brow/subscriptions","organizations_url":"https://api.github.com/users/brow/orgs","repos_url":"https://api.github.com/users/brow/repos","events_url":"https://api.github.com/users/brow/events{/privacy}","received_events_url":"https://api.github.com/users/brow/received_events","type":"User","site_admin":false},"body":"Is this what you're envisioning?\r\n```swift\r\nsignal.observe(SinkOf { event in\r\n    switch event {\r\n        // ...\r\n    }\r\n})\r\n```","created_at":"2015-02-15T03:08:00Z","updated_at":"2015-02-15T03:08:00Z","html_url":"https://github.com/ReactiveCocoa/ReactiveCocoa/pull/1759#discussion_r24719294","pull_request_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/pulls/1759","_links":{"self":{"href":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/pulls/comments/24719294"},"html":{"href":"https://github.com/ReactiveCocoa/ReactiveCocoa/pull/1759#discussion_r24719294"},"pull_request":{"href":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/pulls/1759"}}},"pull_request":{"url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/pulls/1759","id":29326803,"html_url":"https://github.com/ReactiveCocoa/ReactiveCocoa/pull/1759","diff_url":"https://github.com/ReactiveCocoa/ReactiveCocoa/pull/1759.diff","patch_url":"https://github.com/ReactiveCocoa/ReactiveCocoa/pull/1759.patch","issue_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/issues/1759","number":1759,"state":"open","locked":false,"title":"Implement switchToLatest","user":{"login":"brow","id":238331,"avatar_url":"https://avatars.githubusercontent.com/u/238331?v=3","gravatar_id":"","url":"https://api.github.com/users/brow","html_url":"https://github.com/brow","followers_url":"https://api.github.com/users/brow/followers","following_url":"https://api.github.com/users/brow/following{/other_user}","gists_url":"https://api.github.com/users/brow/gists{/gist_id}","starred_url":"https://api.github.com/users/brow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brow/subscriptions","organizations_url":"https://api.github.com/users/brow/orgs","repos_url":"https://api.github.com/users/brow/repos","events_url":"https://api.github.com/users/brow/events{/privacy}","received_events_url":"https://api.github.com/users/brow/received_events","type":"User","site_admin":false},"body":"Towards #1750.\r\n\r\nTested:\r\n- [x] should forward values from the latest inner signal\r\n- [x] should forward an error from an inner signal\r\n- [x] should forward an error from the outer signal\r\n- [x] should complete when the original and latest signals have completed\r\n\r\nTODO:\r\n- [x] Refactor specs with `SignalProducer.buffer`","created_at":"2015-02-14T22:51:51Z","updated_at":"2015-02-15T03:08:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6157c0ff12740f55800b27f664f3d23c89212fcd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/pulls/1759/commits","review_comments_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/pulls/1759/comments","review_comment_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/pulls/comments/{number}","comments_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/issues/1759/comments","statuses_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/statuses/bffd8cdff44fb9bb239ff4bd22e764f505d6c6a7","head":{"label":"brow:switchToLatest","ref":"switchToLatest","sha":"bffd8cdff44fb9bb239ff4bd22e764f505d6c6a7","user":{"login":"brow","id":238331,"avatar_url":"https://avatars.githubusercontent.com/u/238331?v=3","gravatar_id":"","url":"https://api.github.com/users/brow","html_url":"https://github.com/brow","followers_url":"https://api.github.com/users/brow/followers","following_url":"https://api.github.com/users/brow/following{/other_user}","gists_url":"https://api.github.com/users/brow/gists{/gist_id}","starred_url":"https://api.github.com/users/brow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brow/subscriptions","organizations_url":"https://api.github.com/users/brow/orgs","repos_url":"https://api.github.com/users/brow/repos","events_url":"https://api.github.com/users/brow/events{/privacy}","received_events_url":"https://api.github.com/users/brow/received_events","type":"User","site_admin":false},"repo":{"id":12208453,"name":"ReactiveCocoa","full_name":"brow/ReactiveCocoa","owner":{"login":"brow","id":238331,"avatar_url":"https://avatars.githubusercontent.com/u/238331?v=3","gravatar_id":"","url":"https://api.github.com/users/brow","html_url":"https://github.com/brow","followers_url":"https://api.github.com/users/brow/followers","following_url":"https://api.github.com/users/brow/following{/other_user}","gists_url":"https://api.github.com/users/brow/gists{/gist_id}","starred_url":"https://api.github.com/users/brow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brow/subscriptions","organizations_url":"https://api.github.com/users/brow/orgs","repos_url":"https://api.github.com/users/brow/repos","events_url":"https://api.github.com/users/brow/events{/privacy}","received_events_url":"https://api.github.com/users/brow/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/brow/ReactiveCocoa","description":"A framework for composing and transforming streams of values","fork":true,"url":"https://api.github.com/repos/brow/ReactiveCocoa","forks_url":"https://api.github.com/repos/brow/ReactiveCocoa/forks","keys_url":"https://api.github.com/repos/brow/ReactiveCocoa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brow/ReactiveCocoa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brow/ReactiveCocoa/teams","hooks_url":"https://api.github.com/repos/brow/ReactiveCocoa/hooks","issue_events_url":"https://api.github.com/repos/brow/ReactiveCocoa/issues/events{/number}","events_url":"https://api.github.com/repos/brow/ReactiveCocoa/events","assignees_url":"https://api.github.com/repos/brow/ReactiveCocoa/assignees{/user}","branches_url":"https://api.github.com/repos/brow/ReactiveCocoa/branches{/branch}","tags_url":"https://api.github.com/repos/brow/ReactiveCocoa/tags","blobs_url":"https://api.github.com/repos/brow/ReactiveCocoa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brow/ReactiveCocoa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brow/ReactiveCocoa/git/refs{/sha}","trees_url":"https://api.github.com/repos/brow/ReactiveCocoa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brow/ReactiveCocoa/statuses/{sha}","languages_url":"https://api.github.com/repos/brow/ReactiveCocoa/languages","stargazers_url":"https://api.github.com/repos/brow/ReactiveCocoa/stargazers","contributors_url":"https://api.github.com/repos/brow/ReactiveCocoa/contributors","subscribers_url":"https://api.github.com/repos/brow/ReactiveCocoa/subscribers","subscription_url":"https://api.github.com/repos/brow/ReactiveCocoa/subscription","commits_url":"https://api.github.com/repos/brow/ReactiveCocoa/commits{/sha}","git_commits_url":"https://api.github.com/repos/brow/ReactiveCocoa/git/commits{/sha}","comments_url":"https://api.github.com/repos/brow/ReactiveCocoa/comments{/number}","issue_comment_url":"https://api.github.com/repos/brow/ReactiveCocoa/issues/comments/{number}","contents_url":"https://api.github.com/repos/brow/ReactiveCocoa/contents/{+path}","compare_url":"https://api.github.com/repos/brow/ReactiveCocoa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brow/ReactiveCocoa/merges","archive_url":"https://api.github.com/repos/brow/ReactiveCocoa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brow/ReactiveCocoa/downloads","issues_url":"https://api.github.com/repos/brow/ReactiveCocoa/issues{/number}","pulls_url":"https://api.github.com/repos/brow/ReactiveCocoa/pulls{/number}","milestones_url":"https://api.github.com/repos/brow/ReactiveCocoa/milestones{/number}","notifications_url":"https://api.github.com/repos/brow/ReactiveCocoa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brow/ReactiveCocoa/labels{/name}","releases_url":"https://api.github.com/repos/brow/ReactiveCocoa/releases{/id}","created_at":"2013-08-19T06:01:14Z","updated_at":"2013-11-25T20:25:27Z","pushed_at":"2015-02-15T00:18:09Z","git_url":"git://github.com/brow/ReactiveCocoa.git","ssh_url":"git@github.com:brow/ReactiveCocoa.git","clone_url":"https://github.com/brow/ReactiveCocoa.git","svn_url":"https://github.com/brow/ReactiveCocoa","homepage":"","size":8864,"stargazers_count":0,"watchers_count":0,"language":"Objective-C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"2.0-development"}},"base":{"label":"ReactiveCocoa:swift-development","ref":"swift-development","sha":"4e7d978f5ddd476ae883723bc8de15a41d6461d0","user":{"login":"ReactiveCocoa","id":3422977,"avatar_url":"https://avatars.githubusercontent.com/u/3422977?v=3","gravatar_id":"","url":"https://api.github.com/users/ReactiveCocoa","html_url":"https://github.com/ReactiveCocoa","followers_url":"https://api.github.com/users/ReactiveCocoa/followers","following_url":"https://api.github.com/users/ReactiveCocoa/following{/other_user}","gists_url":"https://api.github.com/users/ReactiveCocoa/gists{/gist_id}","starred_url":"https://api.github.com/users/ReactiveCocoa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ReactiveCocoa/subscriptions","organizations_url":"https://api.github.com/users/ReactiveCocoa/orgs","repos_url":"https://api.github.com/users/ReactiveCocoa/repos","events_url":"https://api.github.com/users/ReactiveCocoa/events{/privacy}","received_events_url":"https://api.github.com/users/ReactiveCocoa/received_events","type":"Organization","site_admin":false},"repo":{"id":3606624,"name":"ReactiveCocoa","full_name":"ReactiveCocoa/ReactiveCocoa","owner":{"login":"ReactiveCocoa","id":3422977,"avatar_url":"https://avatars.githubusercontent.com/u/3422977?v=3","gravatar_id":"","url":"https://api.github.com/users/ReactiveCocoa","html_url":"https://github.com/ReactiveCocoa","followers_url":"https://api.github.com/users/ReactiveCocoa/followers","following_url":"https://api.github.com/users/ReactiveCocoa/following{/other_user}","gists_url":"https://api.github.com/users/ReactiveCocoa/gists{/gist_id}","starred_url":"https://api.github.com/users/ReactiveCocoa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ReactiveCocoa/subscriptions","organizations_url":"https://api.github.com/users/ReactiveCocoa/orgs","repos_url":"https://api.github.com/users/ReactiveCocoa/repos","events_url":"https://api.github.com/users/ReactiveCocoa/events{/privacy}","received_events_url":"https://api.github.com/users/ReactiveCocoa/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ReactiveCocoa/ReactiveCocoa","description":"A framework for composing and transforming streams of values","fork":false,"url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa","forks_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/forks","keys_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/teams","hooks_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/hooks","issue_events_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/issues/events{/number}","events_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/events","assignees_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/assignees{/user}","branches_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/branches{/branch}","tags_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/tags","blobs_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/git/refs{/sha}","trees_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/statuses/{sha}","languages_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/languages","stargazers_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/stargazers","contributors_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/contributors","subscribers_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/subscribers","subscription_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/subscription","commits_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/commits{/sha}","git_commits_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/git/commits{/sha}","comments_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/comments{/number}","issue_comment_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/issues/comments/{number}","contents_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/contents/{+path}","compare_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/merges","archive_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/downloads","issues_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/issues{/number}","pulls_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/pulls{/number}","milestones_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/milestones{/number}","notifications_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/labels{/name}","releases_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/releases{/id}","created_at":"2012-03-02T22:11:24Z","updated_at":"2015-02-14T22:12:05Z","pushed_at":"2015-02-14T18:41:27Z","git_url":"git://github.com/ReactiveCocoa/ReactiveCocoa.git","ssh_url":"git@github.com:ReactiveCocoa/ReactiveCocoa.git","clone_url":"https://github.com/ReactiveCocoa/ReactiveCocoa.git","svn_url":"https://github.com/ReactiveCocoa/ReactiveCocoa","homepage":"","size":25699,"stargazers_count":6940,"watchers_count":6940,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":980,"mirror_url":null,"open_issues_count":93,"forks":980,"open_issues":93,"watchers":6940,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/pulls/1759"},"html":{"href":"https://github.com/ReactiveCocoa/ReactiveCocoa/pull/1759"},"issue":{"href":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/issues/1759"},"comments":{"href":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/issues/1759/comments"},"review_comments":{"href":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/pulls/1759/comments"},"review_comment":{"href":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/pulls/1759/commits"},"statuses":{"href":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/statuses/bffd8cdff44fb9bb239ff4bd22e764f505d6c6a7"}}}}