O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Models

Obviously, we can use the Todo model we have used in our backend example, but we want to make our frontend application as functional as possible. There is a functional JSON parsing library named Argo that we can leverage. Let's define our Todo model with Argo:

import Argo import Curry import Runes enum TodoFilter: Int {     case all     case active     case completed     case notSyncedWithBackend     case selected } struct Todo {     let todoId: Int     let name: String     let description: String     let notes: String?     let completed: Bool     let synced: Bool     let selected: Bool? } extension Todo: Decodable {     static func decode(_ json: JSON) -> Decoded<Todo> {         return curry(Todo.init)             <^> json <| "todoId"             <*> json <| "name"             <*> json <| "description"  <*> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required