Instructor: 00:00 How can you handle nullable fields? Imagine, for example, that our users are not required to disclose their gender, so this may well be null. Elm, of course, doesn't have null, but uses maybe instead. In our model, this would be a maybe of gender.
00:21 If I save that now, you can see that this doesn't compile, because my types don't line up. I'm providing a gender where the user function is expecting a maybe of gender.
00:31 For nullable fields, there is a nullable function that takes a decoder and transforms it into an optional decoder, if you like. Now, you can see that this works, and we have gender of nothing. If I change that to say female, then the gender has gone to just female.
00:56 Some JSON APIs will have null for optional fields, but some APIs will leave the field out altogether. If we try running this, you see we get an error decoding the JSON. What we have is not really a nullable value, but rather a completely absent field.
01:12 In this case, we need a slightly different variation, and that is to use a function called maybe. What this is saying is that maybe we have this field. Let me save that, and you can see now that gender is nothing. If I add the gender back in, let's make it male again, then we have just male as expected.