Staying sane with Maybe (maybe vs type)

So just to solidify and condense some of the suggestions on here, it seems to be:

  1. Start with the data (impossible states and make data structures)
  2. Loading states might be best as custom types
  3. Potentially use non-empty lists …
  4. Or default data in your json (instead of a Maybe)? See below
  5. But Maybe types are fine to use, as is Maybe.withDefault.

Maybe.withDefault

@wolfadex I quite like that approach, do you normally just use it for a string or do you also use for other data types?

I understand the general idea or FindKeyedShape, but I can’t quite visualise how that search function might work.

Caseing on a loading type

@ChrisWellsWood I’ve seen this method before of caseing on your model
for noop, loading, loaded, failed which makes sense … but could you expand a little on your custom type records? I understand Page (a title and it’s body), but …

  • Why are you naming things mToken and token? What do they stand for?
  • How do you pass your loaded data to update Page and view when it’s loaded? (I’m assuming MyPageData is the decoder?)

Impossible states

@dta Do you personally have any other examples you could add to that line of thought? Simple ones ideally.

What would a Maybe type look like in the json?

I’m splitting this out into another question, as it brings up the question how to save and represent a type in the json file, be it a Maybe or a type Custom.