

Conceptually the nicest way is to create an automaton that matches any five characters and then compute the intersection between that automaton and the regex automaton. Say you want to compute all strings of length 5 that the automaton can generate. IDK your level of familiarity and don't want to overburden you with things you already get. If you want examples of any specific part of this let me know. It's out of band because you don't guard for special values of your morphologically identical data. If you got Json that was hit by cosmic rays when trying to build your User model, you can fail right then and not build a model and find a way to handle that. So your data is a different shape when it's valid vs when it's invalid, and you can write functions that only accept data that's the valid shape. Data and "this is for sure not meaningful data" are the same shape! So your functions need to handle those cases.īut with tagged unions you can check these things at the edge of the program and thereafter accept that the contents of the tagged data are valid (because you wrote good tests for your decoders). We are testing for special values of the data. Whenever we consume these values, we need to make sure that userId > 0 and email != "" I mean email != "". We use semaphore values: if the user ID is invalid we store -1 (it's JS and there are no unsigned numbers) and if the email address is invalid we store the empty string.

We store the User ID as an integer to keep space down and store the email address as a string. And we want to signal the validity of some data. So in this case we can imagine an app where we don't use any tagged unions and just use primitive types (your strings, booleans, integers, things of that nature). Sure! Sorry that was a little too obtuse.
