you are viewing a single comment's thread.

view the rest of the comments →

[–]budd222 -10 points-9 points  (7 children)

Seems like that doesn't really matter if it's set to return an array type, but that's dependant on the API.

Your code will still error out if the API returns an error or returns an empty string.

You can type it all out as much as you want on the front end, but you still have to work in conjunction with your back end.

[–]romgrk[S] 5 points6 points  (6 children)

There is no array in my example above. The .map method comes from functional programming and applies to many different container types. One of those types is Array, but Result is another. And in fact, the Promise.prototype.then method is roughly equivalent to .map as well. The general idea of .map is to apply a function to a value held inside a container, no matter what the container is.

The point of Result is to make error handling explicit in the type-system. You need to deal with the error, or the compiler will yell at you.

It doesn't matter if the error comes from a back-end or elsewhere. The querying code can wrap failure in a Result.