Hi, I am thrilled to see this book and am learning right out of the gate. I don’t have much experience in this area, and Ch4 is a bit over my head. I was wondering if you could suggest some tutorials or video series that would get me up to speed? I don’t want to burn your time walking me through this on the forum, but if there was some “homework” I could do, please let me know.
For example, I need more detail here:
“To demonstrate, imagine you have a route that returns the HTTP status code 204 No Content. This route fetches a list of users from a database using a function like the one described above and modifies the first user in the list before returning.”
- So, to explain this example, I have created some code like the example in Ch2 and have created a route that returns (aka responds to a GET operation) a list of users to the requesting machine? Is that correct?
- “In order to use the result of that call…” - wait, I thought that I was writing the code that returned the list of users. Why am I unwrapping the result of this? Aren’t I just returning it? Am I confusing what “call” is?
- Where can I find out more about the need to unwrap using map and flatMap? I haven’t seen these before in this context. Or maybe I am just forgetting…
- Please explain more about these functions and why they are used in the situations mentioned. I am a bit lost here.
In #1 in the first mapping code, it says:
“The closure for flatMap(to:) receives the completed future - [User] as its parameter. This .flatMap(to:) returns Future.” - How do I know that it returns this type?
In #3, : “return user.save().map(to: HTTPStatus.self) { user in” - how does this work? I’ve never seen user.save().map(…) before
I basically have similar questions for the flatten section. Perhaps there could be more detail here or analogies used to describe what’s going on.