TL;DR
In the previous post, we sent an HTTP request using Elm architecture. This post is part of the functional language series, and it is based on a remarkable book, Programming Elm Build Safe and Maintainable Front-End Applications by Jeremy Fairbank.
Internet And Maybe
Internet does not guarantee anything. It is not a transaction protocol. When you try to get something over the internet, you could get that value or not. To move the handling of that problem away from developers, Elm handles this in its architecture by introducing. type Maybe
.
When we moved in our Picshare
application form hardcoded pictures to get them over the Internet, we got a Chicken-Egg problem. Picshare
the application requires the initial model to start, but we do HTTP.get to get our initial photo. We need to handle photo null
value. But as this is not part of Picshare
application business logic, the Elm
helps us to handle that logic by introducing Maybe
type:
type Maybe a
= Just a
| Nothing
If there is a value, it Just
returns that value otherwise returns Nothing
.
Follow comments from following gist:
Compile application and open index.html
. For some reason, like button is not shown. If you have a solution for this problem, please post it in comments.
Comments are closed.