{"action":"created","issue":{"url":"https://api.github.com/repos/kzaher/RxFeedback/issues/11","repository_url":"https://api.github.com/repos/kzaher/RxFeedback","labels_url":"https://api.github.com/repos/kzaher/RxFeedback/issues/11/labels{/name}","comments_url":"https://api.github.com/repos/kzaher/RxFeedback/issues/11/comments","events_url":"https://api.github.com/repos/kzaher/RxFeedback/issues/11/events","html_url":"https://github.com/kzaher/RxFeedback/issues/11","id":265508404,"number":11,"title":"[Proposal] - Make FeedbackLoop as a struct","user":{"login":"sergdort","id":4622322,"avatar_url":"https://avatars3.githubusercontent.com/u/4622322?v=4","gravatar_id":"","url":"https://api.github.com/users/sergdort","html_url":"https://github.com/sergdort","followers_url":"https://api.github.com/users/sergdort/followers","following_url":"https://api.github.com/users/sergdort/following{/other_user}","gists_url":"https://api.github.com/users/sergdort/gists{/gist_id}","starred_url":"https://api.github.com/users/sergdort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergdort/subscriptions","organizations_url":"https://api.github.com/users/sergdort/orgs","repos_url":"https://api.github.com/users/sergdort/repos","events_url":"https://api.github.com/users/sergdort/events{/privacy}","received_events_url":"https://api.github.com/users/sergdort/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2017-10-14T17:24:25Z","updated_at":"2017-10-16T19:20:30Z","closed_at":null,"author_association":"NONE","body":"Hi, guys!\r\n\r\nI've been thinking how we can improve API in a way that users won't be able to path their own `FeedbackLoop` as they may use it wrong by not using `scheduler` correctly\r\n\r\nSo here is my proposal:\r\n\r\n```swift\r\npublic struct FeedbackLoop<State, Event> {\r\n    let loop: (ImmediateSchedulerType, Observable<State>) -> Observable<Event>\r\n    \r\n    public init<Control: Equatable>(query: @escaping (State) -> Control?, effects: @escaping (Control) -> Observable<Event>) {\r\n        self.loop = { scheduler, state -> Observable<Event> in\r\n            return state.map(query)\r\n                .distinctUntilChanged { $0 == $1 }\r\n                .flatMapLatest { control -> Observable<Event> in\r\n                    guard let control = control else { return Observable.empty() }\r\n                    \r\n                    return effects(control).enqueue(scheduler)\r\n                }\r\n        }\r\n    }\r\n    \r\n    public init(predicate: @escaping (State) -> Bool, effects: @escaping (State) -> Observable<Event>) {\r\n        self.loop = { scheduler, state -> Observable<Event> in\r\n            return state.flatMapLatest { state -> Observable<Event> in\r\n                guard predicate(state) else { return Observable.empty() }\r\n                \r\n                return effects(state).enqueue(scheduler)\r\n            }\r\n        }\r\n    }\r\n    \r\n    public init(effects: @escaping (State) -> Observable<Event>) {\r\n        self.loop = { scheduler, state in\r\n            return state.flatMapLatest { state in\r\n                return effects(state).enqueue(scheduler)\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n```\r\n\r\nBy exposing only these three available initializers. I guess we can also somehow figure out how something similar can be adopted for `Driver` as well.\r\n\r\nWhat do you guys think?"},"comment":{"url":"https://api.github.com/repos/kzaher/RxFeedback/issues/comments/337004714","html_url":"https://github.com/kzaher/RxFeedback/issues/11#issuecomment-337004714","issue_url":"https://api.github.com/repos/kzaher/RxFeedback/issues/11","id":337004714,"user":{"login":"kzaher","id":1641148,"avatar_url":"https://avatars1.githubusercontent.com/u/1641148?v=4","gravatar_id":"","url":"https://api.github.com/users/kzaher","html_url":"https://github.com/kzaher","followers_url":"https://api.github.com/users/kzaher/followers","following_url":"https://api.github.com/users/kzaher/following{/other_user}","gists_url":"https://api.github.com/users/kzaher/gists{/gist_id}","starred_url":"https://api.github.com/users/kzaher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kzaher/subscriptions","organizations_url":"https://api.github.com/users/kzaher/orgs","repos_url":"https://api.github.com/users/kzaher/repos","events_url":"https://api.github.com/users/kzaher/events{/privacy}","received_events_url":"https://api.github.com/users/kzaher/received_events","type":"User","site_admin":false},"created_at":"2017-10-16T19:20:30Z","updated_at":"2017-10-16T19:20:30Z","author_association":"OWNER","body":"I guess we can probably improve them in some way ..."}}
{"actor":{"display_login":"kzaher"}}