{"id":16886665,"url":"https://github.com/alisoftware/functionalvcdemo","last_synced_at":"2025-04-11T13:53:57.719Z","repository":{"id":137559996,"uuid":"73753498","full_name":"AliSoftware/FunctionalVCDemo","owner":"AliSoftware","description":"Demo for the Functional ViewControllers concept in RxSwift","archived":false,"fork":false,"pushed_at":"2016-11-15T00:55:05.000Z","size":266,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T10:11:50.953Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AliSoftware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-14T22:42:15.000Z","updated_at":"2017-08-10T09:45:44.000Z","dependencies_parsed_at":"2023-04-20T10:15:44.692Z","dependency_job_id":null,"html_url":"https://github.com/AliSoftware/FunctionalVCDemo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliSoftware%2FFunctionalVCDemo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliSoftware%2FFunctionalVCDemo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliSoftware%2FFunctionalVCDemo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliSoftware%2FFunctionalVCDemo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AliSoftware","download_url":"https://codeload.github.com/AliSoftware/FunctionalVCDemo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248412091,"owners_count":21099048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T16:40:37.069Z","updated_at":"2025-04-11T13:53:57.691Z","avatar_url":"https://github.com/AliSoftware.png","language":"Swift","readme":"# FunctionalVCDemo\n\nThis project is a sample app demonstrating the concept of Functional ViewControllers using `RxSwift`.\n\n## Concept\n\nA Functional ViewController is a ViewController that can be used as a function `func show(input: T) -\u003e Observable\u003cU\u003e`. It will display the ViewController to gather data from the user, wait for the user to validate, then emit a `.next` even on the returned `Observable\u003cU\u003e` once validated.\n\n## Advantages\n\nThis pattern is useful to integrate a ViewContoller is a functional workflow, abstracting away the fact that the ViewController is a UI component and instead treating it as an asynchronous function getting inputs and asynchronously returning an output.\n\n## Concept example\n\nImagine you have some Functional VCs that can be exposed in those functions:\n\n* `func pickImage() -\u003e Observable\u003cUIImage\u003e`\n* `func askTitle() -\u003e Observable\u003cString\u003e`\n* `func askNote() -\u003e Observable\u003cInt\u003e`\n\nEach function presents a UIViewController, waits for the user to interact and validate (e.g. `pickImage` will present an `UIImagePickerController` and wait for the user to select an image), and asynchronously return the result (in case of `pickImage`, that's the `UIImage` obvously).\n\nWith this you can easily chain those functional VCs usng classic RxSwift reactive chains:\n\n```swift\nstruct ImageDescription {\n  let image: UIImage?\n  let name: String?\n  let note: Int?\n}\n\nvar imageDesc: ImageDescription()\nself.pickImage()\n  .flatMap({ image in\n    imageDesc.image = image\n    self.askTitle()\n  })\n  .flatMap({ title in\n    imageDesc.title = title\n    self.askNote()\n  })\n  .subscribe(onNext: { note in\n    imageDesc.note = note\n    print(imageDesc)\n  })\n  .addDisposableTo(disposeBag)\n```\n\nThis allows to read the workflow like a chain of steps happening one after the other, hiding away the complexity of asynchronicity.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falisoftware%2Ffunctionalvcdemo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falisoftware%2Ffunctionalvcdemo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falisoftware%2Ffunctionalvcdemo/lists"}